I have a fundamental question about how to use Hibernate.
I have a class Group with a many-to-one relationship with Person. The group class is an agregation composed of various class attributes, one being a User. When the datatbase scripts are generated the resulting entities are Group with a foriegn key named User_Id (Long) and of course User.
If I want to create a new Group and I know the ID of the user that will be associated with that Group, what are my options for saving the Group? From what I can see, I have no option but to first do a load of the User using the user_id, then associate the user object with the new Group object, and then save it. Is there a better/more efficient way of doing this? Shouldn't I be able to simply insert the new Group with the appropirate User_id into the database? Are there best practices around this, or am I doing it just as it should be done?
Thanks for your help!
Aaron.
|