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>