Skip to content
Advertisement

JPA Hibernate Annotation Issue

I have three Entities i’m modeling and am having issues with the associated annotations. I basically have a class that I intend on returning to the caller, a nested listed of Project’s and the Project can contain a nested list of Endpoint’s. It’s a top-level has-a one-to-many, then the nested one-to-many has two one-to-many’s.

I’ve played with @JoinColumn annotations, i’ve attempted to put a @ManyToOne on the other side of the OneToMany’s (but it doesn’t like that it’s a Long..). I’m just fairly new and unsure on how to do this. I think the mappedById is the solution, but i’m uncertain.

Main Issue: This code allows me to “save” to the database, but upon retrieval, the list of Project’s inside the DownDetectorPackage is empty.

A CascadeType.ALL throws referential integrity errors that I don’t completely understand.

JavaScript

JavaScript

JavaScript

Advertisement

Answer

You should be using @JoinColumn instead of mappedBy. MappedBy can be used when you have used @ManyToOne in the other class too, which you haven’t.

So your final class should look something like this (this is applicable for the other classes too which you have mentioned) :

JavaScript

Also, remember to state the parent object name in @JoinColumn annotation, since it would create a column for that foreign key.

Advertisement