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: Informix returning 0 id on save
PostPosted: Wed May 12, 2010 3:30 pm 
Newbie

Joined: Wed May 12, 2010 3:16 pm
Posts: 3
I'm using Hibernate with an Informix database that has a parent table for the id values and a child text table. When inserting into the parent table the generated ID being returned by session.save() is always zero, even though the table does not allow zero and the actual generated id being inserted into the table is greater than zero. Because of this I cannot insert into the text table because of a constraint violation - the id of zero does not actually exist in the parent table so the text with an id of zero cannot be inserted into the text table.

The hibernate xml I have is as follows:

Code:
<hibernate-mapping>
   <class name="org.hibernate.test.TestVo" table="Test_Table">
      <id name="id" type="long">
         <column name="Test_Id_Nbr" />
         <generator class="identity" />
      </id>
      <property name="userid" type="string">
         <column name="Last_Updt_Userid" length="10" not-null="false" />
      </property>
      <property name="timestamp" type="java.util.Calendar">
         <column name="Last_Updt_Ts" not-null="false" />
      </property>
      <set name="descriptions" inverse="true" lazy="false">
         <key>
            <column name="Test_Id_Nbr" not-null="true" />
         </key>
         <one-to-many class="org.hibernate.test.TestTextVo" />
      </set>
   </class>
</hibernate-mapping>


I'm using the org.hibernate.dialect.InformixDialect dialect. Any help would be greatly appreciated.

Thanks!
Mike


Top
 Profile  
 
 Post subject: Re: Informix returning 0 id on save
PostPosted: Wed May 12, 2010 4:04 pm 
Newbie

Joined: Wed May 12, 2010 3:16 pm
Posts: 3
Just as some clarification, the SQL used to get the ID - "select dbinfo('serial8') from systables where tabid=1" - is what's returning 0. It seems to work, and it's the only mode of generator that I can get to work, but it's also what ends up being assigned to my ID, rather than the ID that the table ends up generating, which is killing me.

Thanks,
Mike


Top
 Profile  
 
 Post subject: Re: Informix returning 0 id on save
PostPosted: Wed May 12, 2010 4:09 pm 
Newbie

Joined: Wed May 12, 2010 3:16 pm
Posts: 3
I ended up fixing it by changing my generator to increment - which I can do since mine should be the only process inserting into the table - but I know it's definitely not the preferred way. If anyone knows how to get sequence or native to work, please let me know.

Thanks,
Mike


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