-->
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: Transaction and update
PostPosted: Fri Feb 08, 2008 7:18 am 
Newbie

Joined: Fri Feb 08, 2008 7:14 am
Posts: 4
Hi, i am a dude about transaction, the next code:

Session session = getSessionFactory().openSession();
Transaction tx = session.beginTransaction();
Message message = new Message("Hello World");
session.save(message);
tx.commit();
session.close();

generate:

insert into MESSAGES (MESSAGE_ID, MESSAGE_TEXT, NEXT_MESSAGE_ID)
values (1, 'Hello World', null)

but

Session session = getSessionFactory().openSession();
Transaction tx = session.beginTransaction();
Message message = new Message("Hello World");
session.save(message);
message.setText("22222")
tx.commit();
session.close();

generate:

insert into MESSAGES (MESSAGE_ID, MESSAGE_TEXT, NEXT_MESSAGE_ID)
values (1, '22222', null)


why happen this?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 08, 2008 8:25 am 
Newbie

Joined: Tue Dec 18, 2007 9:15 am
Posts: 14
Because you have commit after you put "2222" string. So, hibernate work in deatched mode, transient mode and persistent mode. If your object travelling in transient, any changes can modify it´s state to be persistent.

_________________
-= DUNKELHEIT =-


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 08, 2008 9:02 am 
Newbie

Joined: Fri Feb 08, 2008 7:14 am
Posts: 4
Grinvon wrote:
Because you have commit after you put "2222" string. So, hibernate work in deatched mode, transient mode and persistent mode. If your object travelling in transient, any changes can modify it´s state to be persistent.


Ok, thanks, then, how check in what mode is hibernate and/or object?


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.