-->
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: map problem: SQL insert, update or delete failed (row not fo
PostPosted: Mon May 03, 2004 7:12 pm 
Newbie

Joined: Mon Apr 26, 2004 5:40 pm
Posts: 5
Hi,

I have a Master - Detail relationship, where there are many different types of details (necessitating specialization). The Master points forward to its Details (I'd like to keep it that way - bidirectionality isn't an option). I need to associate some identifier with each detail record, and store it in the Master - which is naturally a map.

The problem is, when I try to add something to the Master map, I get this exception:

java.lang.RuntimeException: net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)

I turn on P6SPY and I notice that Hibernate is trying to execute an update statement on the Detail table with the index value I'm assiging along with the rest of the Detail record. Why is it deciding to try an update? How do I signal to Hibernate that it should be doing an insert?

Thanks, Steve

Mappings follow.

<hibernate-mapping>
<class name="Detail">
<id name="key">
<generator class="assigned"/>
</id>
<discriminator column="TYPE"/>

<subclass name="SomeDetail" discriminator-value="S">
<property name="name"/>
</subclass>
<subclass name="AnotherDetail" discriminator-value="A">
<property name="serial"/>
</subclass>
</class>
</hibernate-mapping>

<hibernate-mapping>

<joined-subclass name="Master" extends="Super">
<key column="SUPER_ID"/>

<map name="detailMap">
<key column="DETAIL_ID"/>
<index column="MASTER_TO_DETAIL_ID" type="long"/>
<one-to-many class="Detail" />
</map>
</joined-subclass>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 7:51 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
The problem is that you have not specified an appropriate "unsaved value" for your defined id. The default value is "null", which means that any value other than a null will result in an update, rather than an insert because it is not "unsaved". Check out the options http://www.hibernate.org/hib_docs/reference/en/html/mapping.html#mapping-declaration-id and see which one works best for your situation. But this seems to get hairy with assigned ids...

My suggestion: if at all possible, move the id generation logic into an IdentifierGenerator implementation and have Hibernate manage that piece for you.


Top
 Profile  
 
 Post subject: thanks
PostPosted: Mon May 03, 2004 9:27 pm 
Newbie

Joined: Mon Apr 26, 2004 5:40 pm
Posts: 5
Thanks Steve, that makes a lot of sense...

We're using "assigned" for now for other reasons (we have another in-memory persistence system that we use as our backing store for some of our unit tests). I'm wary of "assigned" though, if it becomes a problem we'll definitely look at IdentifierGenerator.

Regards,
Steve


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.