-->
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
PostPosted: Mon Dec 27, 2004 3:05 pm 
Newbie

Joined: Mon Dec 27, 2004 2:52 pm
Posts: 6
Hi!
I've got several problems trying to insert a parent /child relation.

The mapped files :

<class name="beans.Agents" table="agents">

... (properties and id )

<set name="usuaris" lazy="false" inverse="true" cascade="delete">
<key>
<column name="idAgent" />
</key>
<one-to-many class="beans.Usuaris"/>
</set>
</class>


<class name="beans.Usuaris" table="usuaris">

<composite-id name="usuarisKey" class="pw.net.beans.Usuaris$UsuarisKey">
<key-property name="idUsuari" column="idUsuari" type="java.lang.String" length="12"/>
<key-property name="idAgent" column="idAgent" type="java.lang.Integer" length="10"/>
</composite-id>

<many-to-one name="agent" class="beans.Agents" update="false" insert="false" cascade="save-update">
<column name="idAgent"/>
</many-to-one>
...
</class>

I fill the object Agents (the parent one) with all fields, including the Child field, but in Database i can only see one row inserted, the parent one.
What should i do?
I tried to change the attribute : insert="false", in the many to one mapping, but it shows me the following error:

Repeated column in mapping for class beans.Usuaris should be mapped with insert="false" update="false": idAgent


Thanks for advanced, and sorry for my unknowledge.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 27, 2004 4:48 pm 
Regular
Regular

Joined: Mon Oct 06, 2003 7:17 am
Posts: 58
Location: Switzerland
Code:
<set name="usuaris" lazy="false" inverse="true" cascade="delete">
<key>
<column name="idAgent" />
</key>
<one-to-many class="beans.Usuaris"/>
</set>


You have to set the cascade attribute to all or save-update. Otherwise the children will not be saved.

Reto


Top
 Profile  
 
 Post subject: Problem in many to one
PostPosted: Tue Dec 28, 2004 9:06 am 
Newbie

Joined: Mon Dec 27, 2004 2:52 pm
Posts: 6
Sorry but, i tried to put cascade=all in my mapping, like this:

<set name="usuaris" lazy="false" inverse="true" cascade="save-update">
<key>
<column name="idAgent" />
</key>
<one-to-many class="beans.Usuaris" />
</set>

and i found the following exception :

PILA EXCECUCIÓ[
net.sf.hibernate.HibernateException: Batch update row count wrong: 0
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:65)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:127)
....

Can anybody help me please?

Thans for advanced.


Top
 Profile  
 
 Post subject: hi
PostPosted: Thu Jan 20, 2005 4:33 am 
Newbie

Joined: Mon Jan 17, 2005 9:05 am
Posts: 17
Hi, salino,

I am doing the similar test like you. But i am stupid enough stuck here.

I even could not get the data insert into database(parent and child).

Could you post your java codes after session open and before session close? i want to see how to initialize primary key class and set , thanks!


Top
 Profile  
 
 Post subject: Problem with one-to-many
PostPosted: Wed Jan 26, 2005 3:53 am 
Newbie

Joined: Wed Jan 26, 2005 3:48 am
Posts: 1
Hi,

Use [unsaved-value="any"] in mapping file for beans.Usuaris class
it worked for me.see if it fits ur requirment.

Samvi


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.