-->
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 id generation
PostPosted: Tue May 10, 2005 1:18 am 
Newbie

Joined: Tue Feb 08, 2005 1:51 am
Posts: 2
Location: Australia
Hello, All.

I'm having problem with using Informix DB version 7.3, trying to generate sequence. I use "native" as generator and put unsaved-value="0".

In Informix, to generate the ID we have to do INSERT INTO <TABLE> and put '0' in the sequence field and it will automatically assign a sequenced number.

But somehow in Hibernate (version 2.1) I'm getting this error:

org.springframework.dao.DataIntegrityViolationException: (Hibernate operation): data integrity violated by SQL ''; nested exception is java.sql.SQLException: Cannot insert a null into column (gen_ftp_status.gfs_id).
java.sql.SQLException: Cannot insert a null into column (gen_ftp_status.gfs_id).
at com.informix.jdbc.IfxSqli.a(IfxSqli.java:3203)
at com.informix.jdbc.IfxSqli.E(IfxSqli.java:3517)

Is there any way I can insert a "0" instead of null ?

Following is some snippet of my hbm file:

<class
name="com.bigw.generic.bigwDFTP.hibernate.GenFtpStatus"
table="GEN_FTP_STATUS"
>
<meta attribute="class-description" inherit="false">
@hibernate.class
table="GEN_FTP_STATUS"
</meta>

<id
name="gfsId"
type="java.lang.Long"
column="GFS_ID"
unsaved-value="0"
>
<meta attribute="field-description">
@hibernate.id
generator-class="native"
type="java.lang.Long"
column="GFS_ID"

@hibernate.generator-param
name="native"
value="0"
</meta>
<generator class="native"/>
</id>


Is there anything I did wrong?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 20, 2005 8:28 am 
Newbie

Joined: Mon Apr 11, 2005 4:55 am
Posts: 16
check your code. Be sure that you are making something like myObject.setId(new Long(0)) before saving a new one.


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 22, 2005 6:48 pm 
Newbie

Joined: Tue Feb 08, 2005 1:51 am
Posts: 2
Location: Australia
I actually have solved this problem.

If we defined the column one-by-one apparently we still can let the Informix generate the id automatically.(i.e do set for the columns that we want to fill, as normal setXXX(blah))

So, what I did, I just set all the other columns as normal, without setting the Id. So I didn't set the Id setId(new Long(0)). Because this makes the code becomes un-portable to different database.

Thanks anyway for comments.


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.