-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Question regarding the persistence context
PostPosted: Fri Mar 09, 2007 8:24 am 
Beginner
Beginner

Joined: Sat Feb 10, 2007 12:18 pm
Posts: 23
Hi communities

Currently I am reading the book "Java Persistence with Hibernate" but I have a question regarding the persistence context and a detatched object.

I am developing a single user RCP for a friend and first I load all my objects. After that the session is closed. These objects then are used to fill my views and editors. Hibernate is used again when the users whants to save the changes he made in the ui so at this point none of the detatched objects have been modified.

I thought I can do something like this
Code:
session = sessionFactory.openSession();
tx = session.beginnTransaction();

// Vehicles are my Objects
vehicle1.setVin( vinTextField.getText() );

tx.commit();
session.close()


Would vehicle1 be persistent? Or do I have to load this object first (by id), then merge (or update) it and then call my setter-method?

Thx in advance (I hope this was not to confusing)
-- Marc


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 09, 2007 10:46 am 
Regular
Regular

Joined: Fri May 12, 2006 4:05 am
Posts: 106
As I understood the book there are several ways to do this:
1.) you can load the perstient object, then merge the new one
2.) you can just merge it without loading before
3.) if you're sure the object hasn't been loaded before you can just call session.update(vehicle1) somewhere between session.beginTransaction() and tx.commit() to reattach the detached object to the persistence context.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.