• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating entity at the many part of a relationship  RSS feed

Zsolt Berentey
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure if this has already been covered or not. Using CMP 2.0, I have a unidirectional one-to-many relationship, as normally I don't want to look up the one side from the many. To name the kid, I have a User entity which has groups. Groups cannot exist without belonging to a user, so I defined the foreign key to user in the database as NOT NULL.
My question is:
Is it possible to create a group by adding it to the Groups collection of user without violating the NOT NULL constraint of the database when calling group.create()?
Code is sg. like this:
1 GroupLocal group = GroupUtil.getLocalHome().create(groupName);
2 UserLocal user = UserUtil.getLocalHome().findByPrimaryKey(userID);
3 Collection groups = user.getGroups();
4 groups.add(group);
Now the database correctly complains for line 1, that the foreign key cannot be NULL...
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!