Hi, I have a class with a one to many relation to itself (Categories contains Categories). I have no problem setting them right, except when I try to create the parent category and the child category on one turn...
Category parentCat = new Category();
parentCat.setTitle(CAT_SIGNATURE);
Category childCat = new Category();
childCat.setTitle(CHILDCAT_SIGNATURE);
childCat.setParentCategory(parentCat);
parentCat.getChildCategories().add(childCat);
The last line produce a null exception because the Set is null (or course, there's no magic as the model class doesn't have any code to do such a thing).
I've tried to flush and commit but the Set is not created by Hibernate.
From other part off my application (when simply adding a category without putting any child in it) the Set is created when the category object is loaded by Hibernate.
In that case, must I need to create a new Set by myself ?
Thank you
|