Org.hibernate.AssertionFailure: null id with OneToMany / ManyToOne relation

I have a problem with the OneToMany / ManyToOne relation:

Class project:

@OneToMany(fetch = FetchType.EAGER,cascade = CascadeType.ALL, orphanRemoval=true ) @JoinColumn(name="PROJECT_ID", nullable=true) private Set<Person> personlist = new HashSet<Person>(); 

Grade:

 @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) @JoinColumn(name = "PROJECT_ID") private Project project; 

Everything works fine as long as there is at least one person connected to the project in the database. If I create a new project and there is no person in the database, I get a hibernation exception:

 org.hibernate.AssertionFailure: null identifier 

I already set nullable = true for the project class, but this does not work. Anyone ideas?

+4
source share
2 answers

Not sure if this helps try @ManyToOne (fetch = FetchType.LAZY, cascade = CascadeType.ALL, optional = true)

0
source

I have been looking all day for a solution to this problem. I have a solution / job.

 @OneToMany(fetch = FetchType.LAZY,cascade = CascadeType.ALL, orphanRemoval=true ) @JoinColumn(name="PROJECT_ID", nullable=true) private Set<Person> personlist = new HashSet<Person>(); 

I have a similar problem with products and ingredients.

Food may exist without being an ingredient in the recipe. An ingredient cannot exist without food. Thus, we have one zero or many between the ingredient and the food:

RECIPE 1 ------------- 1 .. * INGREDIENT 0 .. * --------- 1 FOOD

Please excuse the description of the trash. I hope you understand.

When the sample type is below EAGER, I get the same problem as you. when he is lazy, I do not.

 @NotFound(action = NotFoundAction.IGNORE) @OneToMany(mappedBy = "food", // the VARIABLE NAME of this class in Ingredient targetEntity = Ingredient.class, // The type that we have many of fetch = FetchType.LAZY, cascade = CascadeType.ALL) private Set<Ingredient> ingredients; 

This is not a good solution, just a job. I think that the choice of EAGER should appear without errors, even if you don’t get anything, then I will have affordable food, and if they are ingredients in recipes, then I have these ingredients available in my subject, and through this recipes, which they are. If they are not ingredients, but simply products on their own, I still want to receive products - it’s just that they will not have any ingredients that are not related to the problem ... but cannot have them if this is the only work around

Does anyone have a better solution? If you do, you can save my life here :-)

0
source

All Articles