• 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

transitive behavior in hibernate

 
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
thanks
 
Look ma! I'm selling my stuff!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic