I am new for hibernate. I met a situation like this:
I have two classes: Parent and Chidren. Questions are:
1) When I insert a new child, the parent's id (primary key) is unknown and will be created automatically by "increment". Now I have this:
Parent p = new Parent();
p.setName("aha");
Children c = new Children();
c.setParent( p );
c.setName("sfs");
If I save/store c, can both p and c be stored in database? It seems I am only able to store c into database and id for p in Children table is null. I thought hibernate should be able to save c first and save p then.
2) About update. Say, I need to check if parent exists in database before I insert any child. But the checking is not based on Parent table's primary key but another field e.g. Parent's name. Should I do the following: a) search existing parent in database, b) set the found patient with new values c) save back to database. It sounds hibernate didn't help me too much on this. I don't know if I am using hibernate correctly. Any suggestion?
Thanks!
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: