-->
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: Can I update an object (an Long) in composite key??
PostPosted: Mon Aug 08, 2005 5:02 pm 
Newbie

Joined: Mon Aug 08, 2005 4:53 pm
Posts: 3
Can I update an object in a composite key??
Example:

Code:
<hibernate-mapping package="br.sapiensit.cadastrounico.programas.dao.hibernate.hbm">

    <class name="br.sapiensit.cadastrounico.programas.pojo.VinculoFamilia" table="TB_CDU_VINCULO_FAMILIA">
        <composite-id name="id" class="br.sapiensit.cadastrounico.programas.pojo.VinculoFamiliaKey">
            <key-many-to-one name="familia" column="CD_FAMILIA" class="br.sapiensit.cadastrounico.cadastrofamilias.pojo.Familia"/>
            <key-many-to-one name="programaMigracao" column="CD_PROGRAMA_MIGRACAO" class="br.sapiensit.cadastrounico.programas.pojo.ProgramaMigracao"/>
            <key-property name="codigoVinculoFamilia" column="CD_VINCULO_FAMILIA" type="java.lang.Long"/>
        </composite-id>

        <property name="flagVinculoValidado" column="FL_VINCULO_VALIDADO" type="java.lang.Short" />

        <many-to-one name="pessoa" column="CD_PESSOA" class="br.sapiensit.cadastrounico.cadastrofamilias.pojo.Pessoa" />
    </class>
   
</hibernate-mapping>


I would like to update the value of property codigoVinculoFamilia.
First I load the object:
someVinculoFamilia = session.load(someVinculoFamiliaKey);
someVinculoFamilia.getId().setCodigoVinculoFamilia(new Long(3));
session.update(someVinculoFamilia);

is this correct!?
Or should I delete the object and then insert!?!?


Top
 Profile  
 
 Post subject: Re: Can I update an object (an Long) in composite key??
PostPosted: Mon Aug 08, 2005 5:07 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
iconst_0 wrote:
Can I update an object in a composite key??
Example:

Code:
<hibernate-mapping package="br.sapiensit.cadastrounico.programas.dao.hibernate.hbm">

    <class name="br.sapiensit.cadastrounico.programas.pojo.VinculoFamilia" table="TB_CDU_VINCULO_FAMILIA">
        <composite-id name="id" class="br.sapiensit.cadastrounico.programas.pojo.VinculoFamiliaKey">
            <key-many-to-one name="familia" column="CD_FAMILIA" class="br.sapiensit.cadastrounico.cadastrofamilias.pojo.Familia"/>
            <key-many-to-one name="programaMigracao" column="CD_PROGRAMA_MIGRACAO" class="br.sapiensit.cadastrounico.programas.pojo.ProgramaMigracao"/>
            <key-property name="codigoVinculoFamilia" column="CD_VINCULO_FAMILIA" type="java.lang.Long"/>
        </composite-id>

        <property name="flagVinculoValidado" column="FL_VINCULO_VALIDADO" type="java.lang.Short" />

        <many-to-one name="pessoa" column="CD_PESSOA" class="br.sapiensit.cadastrounico.cadastrofamilias.pojo.Pessoa" />
    </class>
   
</hibernate-mapping>


I would like to update the value of property codigoVinculoFamilia.
First I load the object:
someVinculoFamilia = session.load(someVinculoFamiliaKey);
someVinculoFamilia.getId().setCodigoVinculoFamilia(new Long(3));
session.update(someVinculoFamilia);

is this correct!?
Or should I delete the object and then insert!?!?


I'm reasonably sure an update would fail - since it would try and update using the new value for that property - so you should delete the old key and insert the new key.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


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.