• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Creating entity at the many part of a relationship

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
Thanks,
Zsolt.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic