I've been looking all day for a solution to this problem. I have a solution / work around.
@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 issue regarding foods and ingredients.
A food can exist without being an ingredient in a recipe. An ingredient can't exist without being a food. So we have a one to zero or many between ingredient and food:
RECIPE 1 ------------- 1..* INGREDIENT 0..* --------- 1 FOOD
Please excuse the rubbish representation above. I hope you get the idea.
When fetch type below is EAGER, I get the same issue as you. when it's set to lazy, I don't.
@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 isn't really a good solution, just a work around. I think an EAGER fetch should fetch without error even if there's nothing to fetch, then I'd have foods available and if they happen to be ingredients in recipes, then I'd have those ingredients availabel in my object, and through that, the recipes they are in. If they are not ingredients, just foods on their own, I still want the foods - it's just they'll have no ingredients associated no problem... but can't have them if this is the only work around
Does anyone have any better solutions to this? If you do you could save my life here :-)