wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Hibernate: Updates all the items of a set - Cascade ‘create’ not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate: Updates all the items of a set - Cascade ‘create’ not working" Watch "Hibernate: Updates all the items of a set - Cascade ‘create’ not working" New topic
Author

Hibernate: Updates all the items of a set - Cascade ‘create’ not working

Sandeep Jindal
Ranch Hand

Joined: Aug 25, 2003
Posts: 180
Hi All,

I am using following data model (changed to make it simpler).

Table: STUDENT, TEACHER, BOOKS_ASSOCIATION, BOOKS_DETAILS.

Student and Teacher have a column whose forign key is BOOKS_ASSC_ID, hbm mapping as following


Books Association Mapping is as following:


and the BOOK_DETAILS table has a coulmn refering to BOOKS_ASSOCIATION table.

The general idea is, the main entity(student,teacher, or anybody else) can have many books. Thus they are having ref to an association key which in turns refer to book details table.

Why there is no direct one to many mapping between main entity (student, teacher, anybody else) is because, books can be issued to any of the main entity. Thus, in order to maintain the forign key reference in BOOK_DETAILS table, this is done.

Now, the problem: Suppose, a Student has issued five books already. Now if I add one more book to the booksDetails set and update the Student object, hibernate runs one insert statement (which is fine), but also runs 6 update statements considering that I have not updated anything in the rest 5 books. I dont want to update the previous items in the association set.

Is there any way to do so? Please also note that I can live with, never updating the BOOK_DETAILS from BOOKS_ASSC or parent entity (STUDENT, TEACHER, etc). I just want two operatonsL: 1) retrieve and 2) add into the bookDetails set.

I tried using cascade="create", but this is not supported. Can anybody please suggest the solution to the problem?

SCJP 5.0
http://sites.google.com/site/duddlutechnologies/home
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate: Updates all the items of a set - Cascade ‘create’ not working
 
Similar Threads
Inheritance / Association in Hibernate
Hibernate- one-to-many association on a foreign key
Hibernate - How to do associations with join tables?
Hibernate POJOs -- association or no-association ?
updating association table