-->
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: Batch Update Objects whit composite-id
PostPosted: Wed Mar 02, 2011 1:34 pm 
Newbie

Joined: Wed Mar 02, 2011 1:22 pm
Posts: 1
Hello everyone! My name is Pasquale and I'm going crazy .... :-)
I have a little problem!!
I need save multiple contacts of the same "Client"!!
this is the mapping file:
Code:
<class catalog="ares" name="ares.beans.Cliente" table="cliente">
    <id name="id" type="java.lang.Integer">
      <column name="id"/>
      <generator class="identity"/>
    </id>
............

<class catalog="ares" name="ares.beans.Contatto" table="contatto">
    <composite-id class="ares.beans.ContattoId" name="id">
      <key-property name="id" type="int">
        <column name="id"/>
      </key-property>
      <key-property name="clienteId" type="int">
        <column name="cliente_id"/>
      </key-property>
    </composite-id>
    <many-to-one class="ares.beans.Cliente" fetch="select" insert="false" name="cliente" update="false">
      <column name="cliente_id" not-null="true"/>
    </many-to-one>

This is the simple code:
Code:
public static void main(String[] args) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();

        for (int i = 0; i < 2; i++) {
            Contatto contatto = new Contatto();
            ContattoId contattoId = new ContattoId();
            contattoId.setClienteId(1);
            contatto.setId(contattoId);
            contatto.setContatto("TEST" + i);
            contatto.setDCreazione(new Date());
            contatto.setDModifica(new Date());
            contatto.setTipo("TELEFONO");
            session.save(contatto);
        }
        tx.commit();
        session.close();
    }

this is the error:
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session]

where am I wrong? :-(


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.