-->
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: composite-id problems moving to Hibernate3
PostPosted: Fri May 20, 2005 1:34 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
Hibernate version:3.0.3

I have a table with a composite id, defined as follows in the hbm:

<composite-id>
<key-property
name="studid"
type="java.lang.Integer"
column="studid"
length="10"
/>
<key-property
name="actid"
type="java.lang.Integer"
column="actid"
length="10"
/>
</composite-id>

After moving from Hibernate 2 to Hibernate 3, I'm now getting a ConstraintViolationException when Hibernate tries to insert a new row saying that actid is null, even though I can see that it has a valid value in the POJO. I couldn't find anything in the forum or FAQs to help.

Has something changed with composite-ids in H3? My code was running fine with H2.

I should mention that both of those properties in the composite-id should actually be key-many-to-one and point to classes, and I will make that change eventually, but this is existing code that I'm trying to migrate with as little impact as possible at this point, so my goal is to make it work as-is.

Here's the stack trace:

17779 ERROR [main] def.AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: could not insert: [org.waterford.db.data.StudAct]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:63)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1859)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2190)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:726)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:320)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at org.waterford.common.data.db.hibernate.HibernateDbSession.commitTransaction(HibernateDbSession.java:92)
at org.waterford.db.business.CoreBO.save(CoreBO.java:108)
at org.waterford.sequencer.engine.Simulator.simulateActivity(Simulator.java:86)
at org.waterford.sequencer.engine.SequencerImpl.simulateActivity(SequencerImpl.java:1939)
at org.waterford.sequencer.engine.SequencerImpl.getNextActivity(SequencerImpl.java:322)
at org.waterford.sequencer.engine.SequencerImpl.getNextActivity(SequencerImpl.java:129)
at org.waterford.sequencer.engine.SequencerLauncher.main(SequencerLauncher.java:299)
Caused by: com.inet.tds.SQLException: Msg 515, Level 16, State 2, Line 1, Sqlstate 23000
[ITNEW]Cannot insert the value NULL into column 'ActId', table 'Ems.dbo.StudAct'; column does not allow nulls. INSERT fails.
at com.inet.tds.g.a(Unknown Source)
at com.inet.tds.g.a(Unknown Source)
at com.inet.tds.b.new(Unknown Source)
at com.inet.tds.b.executeUpdate(Unknown Source)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:104)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1843)
... 17 more


Here's the sql statement:

Hibernate: insert into StudAct (Status, UseCount, TotEnabledTime, TotTimeOutCnt, TotRepeatAudioCnt, TotActTime, studid, actid) values (?, ?, ?, ?, ?, ?, ?, ?)

Why isn't it using my actid value from the POJO??

Thanks in advance.

Nathan


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 20, 2005 2:03 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
Some follow-up info on the problem is that the code before was using Session.saveOrUpdateCopy() previously to save the new instance, and I changed it to merge() based on the migration guide.

The javadoc on merge says :

Quote:
If the given instance is unsaved, save a copy of and return it as a newly persistent instance.


I assumed that meant that the object that gets returned should be the same as the object i passed in, but this is not that case. the object that is returned from merge() has all null values. I'm sure this is why I'm getting the error, but I still don't know what I'm doing wrong.

This is probably an easy one. I appreciate anyone's help!

Nathan


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.