-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate : Id value not set upon save
PostPosted: Fri Jun 11, 2010 6:04 am 
Newbie

Joined: Fri Jun 11, 2010 5:53 am
Posts: 4
Hi,

I'm trying a very simple insert of an object and I'm noticing that the ID of the object is not being set in my pojo after the call to save. I thought that hibernate was supposed to set the ID after the object is persisted? Am I wrong in my understanding?

As a result, my subsequent code which needs the object id is not going through. I'm getting below error because of this issue.

Since the id is not returned after save, the default value for long which is 0 is set for further code, as result am getting foreign key violation because the parent table doesnt contain a record with key value as 0.

Caused by: java.sql.SQLException: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_PROV_SET_ASSOC_PROV_PID". The conflict occurred in database "alineo", table "PROVIDER.PROVIDER", column 'PROVIDER_PID'.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:365)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2781)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2224)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:628)
at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:525)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:487)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:421)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:105)
at org.hibernate.engine.query.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:165)


Mapping file :
------------

the id details in the mapping file.

<id name="pid" type="long" column="CUSTOMER_PID">
<generator class="native">
<param name="sequence">CUSTOMER.SQ_CUSTOMER</param>
</generator>
</id>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.