-->
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.  [ 10 posts ] 
Author Message
 Post subject: session.save() didn't write to db
PostPosted: Thu Oct 13, 2005 12:06 pm 
Newbie

Joined: Thu Oct 13, 2005 11:53 am
Posts: 6
I have a simple class ProcessInstance which maps to procinstance table. I'm using code below to update status field. The problem I have is, the new status didn't get updated in the db out of every several calls to the java code. I enabled show_sql and was able to see if the sql is generated or not.


Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0.5

Mapping documents:
<hibernate-configuration>

<session-factory>

<!-- Database connection settings -->
<property name="connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="connection.url">jdbc:mysql://10.10.1.14/xxx</property>
<property name="connection.username">xxx</property>
<property name="connection.password">xxx</property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>

<!-- Drop and re-create the database schema on startup -->
<!--property name="hbm2ddl.auto">create</property-->

<mapping resource="com/danucom/mforms/data/ProcessInstance.hbm.xml"/>

</session-factory>

</hibernate-configuration>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
package="com.danucom.mforms.data">
<class name="ProcessInstance" table="procinstance">
<comment>A process instance</comment>
<id name="id">
<generator class="native"/>
</id>
<property name="data"/>
<property name="status"/>
<property name="mboxId" column="mboxid"/>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
s.setCacheMode(CacheMode.REFRESH);
s.setFlushMode(FlushMode.ALWAYS);
Transaction tx = null;
tx = session.beginTransaction();
ProcessInstance procInstance = (ProcessInstance) session.load(ProcessInstance.class, new Long(procInstanceId));
procInstance.setStatus(newStatus);
session.save(procInstance);
tx.commit();

Full stack trace of any exception that occurs: NONE

Name and version of the database you are using:
MySQL 4.0.25 and mysql-connector-java-3.0.15-ga

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 13, 2005 1:15 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
Session.save means insert. Use update() or saveOrUpdate().


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 13, 2005 1:22 pm 
Newbie

Joined: Thu Oct 13, 2005 11:53 am
Posts: 6
dennisbyrne wrote:
Session.save means insert. Use update() or saveOrUpdate().


The generated sql is "update..." Hibernate is probably smart enough to figure out which sql command to use. I'll change this and see if the problem still occurs though.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 13, 2005 1:34 pm 
Newbie

Joined: Thu Oct 13, 2005 11:53 am
Posts: 6
Change save() to update() doesn't help.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 13, 2005 1:42 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
actually, automatic dirty checking means that you can just remove that line altogether.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 13, 2005 3:42 pm 
Newbie

Joined: Thu Oct 13, 2005 11:53 am
Posts: 6
dennisbyrne wrote:
actually, automatic dirty checking means that you can just remove that line altogether.

Anyway, that doesn't look like the cause of my problem.

Here is more info about my configuration:

The mentioned java code is a part of a Axis-based web service deployed on Tomcat 5.0.19. Every call is probably handled in separate thread. Thus it is a multi-threaded environment. Hibernate session objects are stored in thread local variable.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 9:51 am 
Newbie

Joined: Thu Oct 13, 2005 11:53 am
Posts: 6
This is such a simple program but the problem is strange. Anyone out there can help? Did I miss anything in the config or java code?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 12:25 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Does the update happen and then the change is just not committed? Or does the update not happen?

Also, why FlushMode.ALWAYS?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 3:27 pm 
Newbie

Joined: Thu Oct 13, 2005 11:53 am
Posts: 6
steve wrote:
Does the update happen and then the change is just not committed? Or does the update not happen?

Also, why FlushMode.ALWAYS?

update does not happen.
I'm not very sure how and when FlushMode.ALWAYS applies, just want to make sure my change get stored.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 7:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Almost always a good idea to *not* muck with the flush mode unless you have a very specific reason.

What is the type of that status field?


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