-->
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.  [ 4 posts ] 
Author Message
 Post subject: session.update() doesn't update persistence data as expected
PostPosted: Mon Feb 23, 2004 4:12 am 
Newbie

Joined: Mon Feb 23, 2004 3:48 am
Posts: 1
Hi there,

I am new to Hibernate 2.1 and having some problems with session.update() in following code snippet in that the update() method doesn't update persistence data as expected. However the load(), find() all work fine.

----------------------------------------------------------------------------------
public void updateOrganisationEmail (Long oid, String email, RunContext runContext) throws HibernateException, Exception
{
java.sql.Connection databaseConnection = null;
Session session = null;
Transaction tx = null;

try {
databaseConnection = DatabaseConnectionManager.getConnection (BaseSystemConfig.isConnectionPoolingModeOnForDataSource (runContext.getDataSourceName ()), runContext);
session = sessionFactory.openSession (databaseConnection);
tx = session.beginTransaction ();
Organisation current = (Organisation) session.load (Organisation.class, oid);
current.setEmail (email);
session.update (current);
tx.commit ();
}
...
}
------------------------------------------------------------------------------------

And the Organisation.hbm.xml is as follows,

------------------------------------------------------------------------------------
<id
name="id"
type="java.lang.Long"
column="ID"
>
<generator class="assigned" />
</id>

<version
name="updateId"
type="java.lang.Integer"
column="UPDATE_ID"
/>
...
<property
name="phone"
type="java.lang.String"
column="PHONE"
length="32"
/>
<property
name="email"
type="java.lang.String"
column="EMAIL"
length="255"
/>
...
----------------------------------------------------------------------------------

I would be grateful if someone can help.

Thanks
Ray


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2004 7:29 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Try doing session.flush() before the commit.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2004 11:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
(1) you do not need to explicitly call update() for an object that is already associated with the session
(2) you do NOT need to explicitly call flush() if you have called Transaction.commit()

I do not know why it is not working, but I'm pretty satisfied that you will be able to resolve this by yourself. Enable Hibernate logging to verify that Hibernate is issuing an SQL UPDATE (I'm sure it is).

Then go check that you are connected to the right database, etc, etc,,,,


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2004 11:11 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Ah yes, in the case you are using MySQL, check that you are using InnoDB tables.


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