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,
|