Did not understand wat was meant in the todo in the persistance.xml so asked for help on the (digital) lab session and figured out what was meant by the todo. Was succsesfull in verifying the installation afterwards.
Step 5 in the tutorial mentions that we use lombok for simplifying the data object code, by auto-generationg getters and setters. Tried to copy paste the provided code but IntelliJ marked the lombok package as missing. Tried to add it as a dependency in the pom.xml but alas no result. Tried to add the pom.xml snippet provided at https://mvnrepository.com/artifact/org.projectlombok/lombok/1.18.12 but no better result either.
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>
In the depenencies tab in IntelliJ the lombok package is not present. Suspect this means that maven has not downloaded the jar.
Tried to run 'mvn clean install' with the hope that the dependencies would be reloaded.
Searched on Google with "dependency red in intellj" and one of the suggestions said to restart intellij. This fixed the issue.
This could probably have been solved a different way. One possible root problem is that IntellJ uses a maven that is bundeled with and not the seperate installed maven from last lab. Not sure if this is the case though.
Then found out it by this blogpost that it was possible by ctr+shift+a to bring up the actions menu and use the action "Reload all Maven Projects". Can verify that this would have worked as the issue is fixed by another student that did this and it verifiably fixed the issue.
On step 6 in the tutorial 2 hours were spent trying to follow the tutorial step of making a new project. The project structure was incorrect for every iteration that was tried. The fix was to not follow the tutorial but instead just edit the persistance.xml iterativly until the Unit test were green. The unit tests were green on one run but any run after, one test named checkFamily, fails. Dont know why. Did not try to fix it. Skipped this as it was green once before. The problem may be that in the setup of the DB enter new data in a table on each testrun, ie bad testsetup.
Inspecting and connectig the database was done using this tutorial with Datagrip, the database IDE from Jetbrains. This could also be done in IntelliJ Ultimate from the databases tab.
Getting some diagrams was done following using this
Here is an example of a table made:
Here is a diagram of the tables made:
- Made all the classes, filled in the fields and used the lombok package to not have to write getters and setters.
- Then had to look at previous tutorial to see how they handled decorating.
- Then had to look at the presentation slides for types of relations between the objects.
- Then decorated some fields and discussed with other students how to move forward. Turns out you need a List for things in classes that have a * to many relations.
- Should not the CreditCard have a relation back to the person? A creditcard should know who owns it.
- Should every side of a many to many relationships have the decorator? No, only the owning side
- Made test and it failed. Suddenly Java compiler did not find a symbol in TODO, a class not changed since the previous part of the assignment. To fix this I swapped @Data tag over @Entity tag.
Same with person. Did not work changing the tagsEither I get stack overflow(!) or compilation errors.
After some trial and error by trying different decorating with a mappedBy decorator the most helpful exception is this one:
Exception Description: An incompatible mapping has been encountered between [class no.hvl.dat250.jpa.basicexample.banking.Person] and [class no.hvl.dat250.jpa.basicexample.banking.Address]. This usually occurs when the cardinality of a mapping does not correspond with the cardinality of its backpointer.
This is as far the debugging was able to do. Was not able to work out the root of the problem here.
- Changed types of the List from ArrayList til List. This was maybe the root problem.
- Changed the decorator of Person class to Many-To-Many, which was in the first iteration but because of above problem a StackOverflow was thrown.
- Changed the mappedBy of the Many-To-Many decorator of Person class to be the residents, not id, by suggestion from the TA.
- Reverted the change of Person2 class to Person
- Deleted all the old tables in the database by hand.
- Ran the test once more. Then the object was persisted and the test was passed.
These steps were made to fix the previous java exceptions.
Can see from by example the following example that the object was persisted:
This is the persistence view of the project:
This is what tables were made in the database in the end:
Do not know where SEQUENCE table came from...