-->
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: Many-to-many error on update
PostPosted: Sat May 15, 2010 5:10 am 
Newbie

Joined: Sat Mar 27, 2010 11:51 am
Posts: 6
Hy people,

I havew found a very strange problem:

I put the java code of my dao:

Code:
Medico medico = (Medico) session.load(Medico.class, bean.getIdMedico());
medico.setNome(bean.getNome());
medico.setCognome(bean.getCognome());
session.save(medico);

if ( (Integer) bean.getAgente().getValue() > 0  ) {
    Agente agente = (Agente) session.load(Agente.class, (Integer) bean.getAgente().getValue());
    medico.getAgentes().add(agente);               
}
         
Integer id = (Integer) session.save(medico);           
transaction.commit();         



when the program arrives to commit() gives me this error :

WARN - SQL Error: 1062, SQLState: 23000 - org.hibernate.util.JDBCExceptionReporter
ERROR - Duplicate entry '1-1' for key 1 - org.hibernate.util.JDBCExceptionReporter
ERROR - Could not synchronize database state with session - org.hibernate.event.def.AbstractFlushingEventListener
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)


this is a part of the mapping file for MEdico.java

Code:
       <set name="agentes" inverse="false" table="agente2medico">
            <key>
                <column name="ID_MEDICO" not-null="true" />
            </key>
            <many-to-many entity-name="it.hibernate.beans.Agente">
                <column name="ID_AGENTE" not-null="true" />
            </many-to-many>
        </set>


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.