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.  [ 5 posts ] 
Author Message
 Post subject: Problem with one-to-many association (save)
PostPosted: Fri Nov 07, 2003 9:47 am 
Newbie

Joined: Fri Nov 07, 2003 9:26 am
Posts: 3
hello,

I try to make a one-to-many association from a class to itself but
I got an error described at the end of this mail.

Here is a part of the code of the class :



------JAVA -----------
public class Keyword {

protected Set MyKeyWords;
.........................................
.........................................
}
------JAVA -----------

,here is a part of main code :


-----JAVA---------------
Set myset = new HashSet();

Keyword kw1 = new Keyword( );
myset.add(kw1);

Keyword kw2 = new Keyword( );
myset.add(kw2);

kw = new Keyword( );
kw.setMyKeyWords(myset);

session.save( kw );
..........................................
.........................................

-----JAVA---------------


,here is ly mapping file :



-----MAPPING---------------

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>

<class name="hb.Keyword"
table="keywords">

<id name="id"
type="integer"
column="id"
unsaved-value="null">
<generator class="identity"/>
</id>

<set name="MyKeyWords">
<key column="clef_keyword"/>
<one-to-many class="hb.Keyword"/>
</set>

</class>
</hibernate-mapping>
-----MAPPING---------------

When I execute the code, I got the following error :


[java] Hibernate: insert into keywords (NAME) values (?)
[java] Hibernate: select @@identity
[java] Hibernate: update keywords set NAME=? where id=?
[java] net.sf.hibernate.HibernateException: SQL update or deletion failed (row not found)
[java] at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(Unknown Source)
[java] at net.sf.hibernate.persister.EntityPersister.update(Unknown Source)
[java] at net.sf.hibernate.persister.EntityPersister.update(Unknown Source)
[java] at net.sf.hibernate.impl.ScheduledUpdate.execute(Unknown Source)
[java] at net.sf.hibernate.impl.SessionImpl.executeAll(Unknown Source)
[java] at net.sf.hibernate.impl.SessionImpl.execute(Unknown Source)
[java] at net.sf.hibernate.impl.SessionImpl.flush(Unknown Source)
[java] at net.sf.hibernate.transaction.JDBCTransaction.commit(Unknown Source)
[java] at Main.main(Unknown Source)
[java] Java Result: 1

If I save kw1, kw2 and kw separately, It works. How to avoid to save kw1 and kw2 ?

Thanks a lot.

LF


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 07, 2003 10:21 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code:
<set name="MyKeyWords" cascade="save-update">

_________________
Emmanuel


Top
 Profile  
 
 Post subject: it doesn't work
PostPosted: Fri Nov 07, 2003 12:04 pm 
Newbie

Joined: Fri Nov 07, 2003 9:26 am
Posts: 3
Thank you epbernard for your quick reply but unfortunately it
doesn't work. The option cascade=save-update" has no effect....
I got always the same error.

Thank you for your help.

LF


Top
 Profile  
 
 Post subject: ditto.. same error...
PostPosted: Wed Nov 12, 2003 5:19 pm 
Beginner
Beginner

Joined: Tue Nov 04, 2003 2:31 pm
Posts: 28
Location: Florida, US
I am also encountering similar problem...


Code:
16:17:01,988 ERROR [STDERR] net.sf.hibernate.HibernateException: SQL update or d
eletion failed (row not found)
        at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatche
r.java:25)
        at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.jav
a:642)
        at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.jav
a:611)
        at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:31
)
        at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2100)
        at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2062)
        at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2005)
        at com.nielsenmedia.myEVNTS.server.ProcessEchoEJB.flushSession(ProcessEc
hoEJB.java:336)
        at com.nielsenmedia.myEVNTS.server.ProcessEchoEJB.testWithHibernate(Proc
essEchoEJB.java:172)


If we see my mapping file

Quote:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.nielsenmedia.myEVNTS.DistributorProgram" table="dist_program">

<!-- A 32 hex character is our surrogate key. It's automatically
generated by Hibernate with the UUID pattern. -->
<id name="programID" type="string" unsaved-value="null" >
<column name="PROGRAM_ID" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<!-- A program has to have a name, but it shouldn' be too long. -->
<property name="programName">
<column name="PROGRAM_NAME" sql-type="varchar(16)" not-null="true"/>
</property>

<property name="duration">
<column name="PROGRAM_DURATION" sql-type="int" not-null="true"/>
</property>
<list name = "episodes" table="episode" inverse="true" lazy="true" cascade="save-update">
<key column="PROGRAM_ID_FK"/>
<index column="EPISODE_ID"/>
<one-to-many class="com.nielsenmedia.myEVNTS.Episode"/>
</list>
</class>

<class name="com.nielsenmedia.myEVNTS.Episode" table="episode" dynamic-update="true" dynamic-insert="true" >
<id name="episodeID" column="EPISODE_ID"> <generator class="native"/> </id>


<property name="episodeName">
<column name="EPISODE_NAME" sql-type="varchar(16)"/>
</property>
<property name="episodeNo">
<column name="EPISODE_NO" sql-type="int"/>
</property>
<many-to-one name="distributorProgram" column="PROGRAM_ID_FK" not-null="true"/>

</class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 12, 2003 7:38 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
ludofleur,

Quote:
Hibernate: insert into keywords (NAME) values (?)


What is NAME? I see no such a property in your mapping...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.