-->
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: Problem with one-to-many collection when inserting
PostPosted: Tue Jul 27, 2010 2:58 am 
Newbie

Joined: Mon Jul 26, 2010 9:58 am
Posts: 6
Hi all,

I have an entity called "Expediente" which has a collection of "Ambito".

Expediente hbm looks like this:
Code:
<hibernate-mapping>
    <class name="es.Expediente" table="EXPEDIENTE">
        <id name="id" type="java.lang.Integer">
            <column name="ID" precision="22" scale="0" />
            <generator class="sequence">
            <param name="sequence">SQ_EXP</param>
         </generator>
        </id>
        <property name="codigo" type="java.lang.String">
            <column name="CODIGO" length="30" />
        </property>
        [...MORE PROPERTIES...]
        <set name="Ambito" table="EXP_AMBITO" inverse="true" cascade="save-update" lazy="false" fetch="join">
            <key>
                <column name="ID_EXP" precision="22" scale="0" not-null="true" />
            </key>
            <one-to-many class="es.xunta.cptopt.sxeuweb.pojo.SxeuExpAmbitoPojo" />
        </set>
    </class>
</hibernate-mapping>


Ambito hbm is as follows:

Code:
<hibernate-mapping>
    <class name="es.Ambito" table="EXP_AMBITO">
        <composite-id name="id" class="es.ExpAmbitoId">
            <key-property name="idExp" type="java.lang.Integer">
                <column name="ID_EXP" precision="22" scale="0" />
            </key-property>
            <key-property name="idTipoAmbito" type="java.lang.Integer">
                <column name="ID_TIPO_AMBITO" precision="22" scale="0" />
            </key-property>
            <key-property name="codigoAmbito" type="java.lang.String">
                <column name="CODIGO_AMBITO" length="20" />
            </key-property>
        </composite-id>
        <many-to-one name="sxeuExpPojo" class="es.xunta.cptopt.sxeuweb.pojo.SxeuExpPojo" update="false" insert="false" fetch="select">
            <column name="ID_EXP" precision="22" scale="0" not-null="true" />
        </many-to-one>
        [...MORE PROPERTIES...]
    </class>
</hibernate-mapping>


And when I try to persist an object from Expediente class I get an error indicating that I can't save "Ambito" without the Expediente id...

I tried without cascade="save-update" and saving Expediente first and then the Ambito collection but when later I update Expediente it tries to update the existing Ambito records that are related to the Expediente object and I get an error indicating that some of them doesn't exist, which is true because the collection has changed.

What can I do to get this working?

Thank you...


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.