-->
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: saveOrUpdate
PostPosted: Wed Apr 14, 2010 7:00 pm 
Newbie

Joined: Wed Apr 14, 2010 5:51 pm
Posts: 1
Hi,
I have very strange problem using saveOrUpdate. Basically I am trying to save transient object to DB and operation seems to go through fine (I get back an id), but when I check the DB nothing appears in the table. Now to make things even more strange when I try to insert some dummy manually I can do it, and the auto incremented id that I get is not 1 (which should be the case if hibernate did not even try to insert), but rather something like 25, meaning that there were 25 recs inserted before. Further, when I try to save some records (through Hibernate) to other table, the operation succeeds and I can see the record. Have any one seen anything like that? I have a feeling that it is a problem with my definition, but cannot see anything obvious. Here is the simple code I use to save:

try {
SessionFactory factory = HibernateUtil.getSessionFactory();
Session session = factory.openSession();
session.saveOrUpdate(obj_);
session.flush();
session.close();
}
catch(Exception e) {

}

As shown, I open/close the session for each request. Below is my xml mapping file:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Mar 31, 2010 9:59:32 AM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="org.semfa.persist.Sblraw" table="Sblraw" catalog="sports">
<id name="sblId" type="java.lang.Integer" unsaved-value="0">
<column name="sblId" />
<generator class="identity" />
</id>
<property name="dateTime" type="timestamp">
<column name="dateTime" length="19" />
</property>
<property name="spId" type="string">
<column name="spId" length="20" />
</property>
<property name="spbId" type="string">
<column name="spbId" length="50" />
</property>
<property name="gDate" type="timestamp">
<column name="gDate" length="19" />
</property>
<property name="t1id" type="string">
<column name="t1Id" length="100" />
</property>
<property name="t2id" type="string">
<column name="t2Id" length="100" />
</property>
<property name="bType" type="string">
<column name="bType" length="20" />
</property>
<property name="bsType" type="string">
<column name="bsType" length="256" />
</property>
<property name="wldType" type="java.lang.Character">
<column name="wldType" length="1" />
</property>
<property name="period" type="java.lang.Float">
<column name="period" precision="12" scale="0" />
</property>
<property name="lType" type="string">
<column name="lType" length="2" />
</property>
<property name="size" type="java.lang.Float">
<column name="size" precision="12" scale="0" />
</property>
<property name="ln" type="java.lang.Float">
<column name="ln" precision="12" scale="0" />
</property>
<property name="ladjust" type="java.lang.Float">
<column name="ladjust" precision="12" scale="0" />
</property>
<property name="rn" type="java.lang.Integer">
<column name="rn" />
</property>
<property name="p1id" type="string">
<column name="p1Id" length="50" />
</property>
<property name="p2id" type="string">
<column name="p2Id" length="20" />
</property>
<property name="gNo" type="java.lang.Integer">
<column name="gNo" />
</property>
</class>
</hibernate-mapping>

I also have similar problem with update (using the same code above). I do not get any errors, but nothing gets updated in DB.

Thanks,


Top
 Profile  
 
 Post subject: Re: saveOrUpdate
PostPosted: Thu Apr 15, 2010 2:05 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
You are not committing the transaction. Check this example code template: http://docs.jboss.org/hibernate/stable/ ... nonmanaged


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.