• Post Reply Bookmark Topic Watch Topic
  • New Topic

transitive behavior in hibernate  RSS feed

David Spades
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is using transitive persistence a recommended practice in hibernate. perhaps in the case of creating a brand new order, order header and detail must be persisted in transitive manner. but lets say in a case where we wantto assign a new student into an already exiting classroom where this classroom has dependency to a teacher. Surely we don't need to load the entire object graph (classroom, teacher, subjects, other students already assigned to the classroom, etc). in the old days (without hibernate), we just update the classroom_id field in student table to the appropriate value. so we can issue just one statement (using subquery) when we know which classroom the student will be assigned to (insert into student (student_name,classroom_id) values ("John Smith", select id from classroom where name="P3C"). So, what is the best practice? is there a way to modify transitive behavior on runtime (overriding the cascade attribute in the mapping)? or is there another pattern in hibernate I'm not aware of? because I think it's possible we want to apply transitive behavior for a class hierarchy, but we also want the transitive behavior not to be used at that same class hierarchy at a certain scenario.
The second question, normally (for the student classroom sample above), I query the classroom, and then assign the retrieved classroom object to student object, and then persist the student object. But since I'm using @trnasactional, querying the classroom would open and close session and then opening a different session to persist student object. Is this correct?
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!