-->
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.  [ 3 posts ] 
Author Message
 Post subject: Simple Detached Object question
PostPosted: Mon Oct 01, 2007 11:35 am 
Newbie

Joined: Mon Oct 01, 2007 11:29 am
Posts: 2
Using Hibernate Core.

I am having problems getting a detached instance of a Role object to be reattached and have the new values persisted.


Code:
session = HibernateUtil.getSessionFactory().openSession();
Role r = (Role)session.get(Role.class, "Manager");
session.close();

r.setRoleName("Manager NAME EDITED");

session = HibernateUtil.getSessionFactory().openSession();
session.update(r);
session.close();


The SQL output shows a SELECT statement instead of an UPDATE statement. This means the the role name I have edited does not persist.

Have I misunderstood the concept of detaching and reattaching objects?

From what I know, it is possible for the original session to close and have the detached object to reattach in the new session.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 01, 2007 12:52 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
It might have something to do with the flushMode. Try to flush the session before closing it and see if that helps.

Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 01, 2007 6:55 pm 
Newbie

Joined: Mon Oct 01, 2007 11:29 am
Posts: 2
farzad wrote:
It might have something to do with the flushMode. Try to flush the session before closing it and see if that helps.

Farzad-


Thanks. I had to add in transaction management before it could work ;)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.