Hello.
I have three entities called (spanish) Macroproceso, Proceso and TipoEntregable. Macroproceso has many Proceso and Proceso has many TipoEntregable. All the keys are natural keys:
- Macroproceso has "codigo".
- Proceso has "codigo" and "codigo_macroproceso" because codigo is not unique. "codigo_macroproceso" is also FK to Macroproceso.
- TipoEntregable has "codigo", "codigo_proceso" and "codigo_macroproceso" because codigo is not unique. "codigo_macroproceso" and "codigo_proceso" are also FK to Proceso.
The problem is when I try to perform an insert (save() method) and then I do the commit(). I know natural keys and composites keys like theese are not recommended, but I need to do it this mazy way...
Please, could anyone tell me where is the mistake? I'll know paste all the information.
Ah, why I see questions marks instead of the inserted values in the log? is there a way to see the values? (i refer to: insert into TIPOS_ENTREGABLE (NOMBRE, CODIGO, CODIGO_MACROPROCESO, CODIGO_PROCESO) values (?, ?, ?, ?)).
Here are the POJOs for the persistente entities:
Code:
public class Macroproceso {
private String codigo; // PK (natural, app assigned, single)
private String descripcion;
private Set<Proceso> procesos; // ONE-TO-MANY PROCESOS
...
}
public class Proceso {
private ProcesoId id; // PK (natural, app assigned, composite)
private String descripcion;
private Set<TipoEntregable> tiposDeEntregable; // ONE-TO-MANY TIPOS_ENTREGABLES
...
}
public class TipoEntregable {
private TipoEntregableId id; // PK (natural, app assigned, composite)
private String nombre;
...
}
And here, you can see the classes for the composites ids:
Code:
public class ProcesoId implements Serializable {
private String codigoProceso;
private Macroproceso macroproceso; // FK MANY-TO-ONE MACROPROCESOS
...
}
public class TipoEntregableId implements Serializable {
private String codigoTipoEntregable;
private Proceso proceso; // FK MANY-TO-ONE PROCESOS
...
}
And here are the mappings (just the class elements of the three xml sources):
Code:
for macroprocesos:
<class name="Macroproceso" table="MACROPROCESOS">
<id name="codigo" column="CODIGO" length="3">
<generator class="assigned"/>
</id>
<property name="descripcion" column="DESCRIPCION" />
<set name="procesos" table="PROCESOS">
<key>
<column name="CODIGO_MACROPROCESO" />
</key>
<one-to-many class="Proceso" />
</set>
</class>
for procesos:
<class name="Proceso" table="PROCESOS">
<composite-id name="id" class="ProcesoId">
<key-property name="codigoProceso" column="CODIGO"/>
<key-many-to-one name="macroproceso" column="CODIGO_MACROPROCESO" class="Macroproceso"/>
</composite-id>
<property name="descripcion" column="DESCRIPCION" />
<set name="tiposDeEntregable" inverse="true">
<key>
<column name="CODIGO_PROCESO"/>
<column name="CODIGO_MACROPROCESO"/>
</key>
<one-to-many class="TipoEntregable"/>
</set>
</class>
for tipos entregable:
<class name="TipoEntregable" table="TIPOS_ENTREGABLE">
<composite-id name="id" class="TipoEntregableId">
<key-property name="codigoTipoEntregable" column="CODIGO"/>
<key-many-to-one name="proceso" class="Proceso">
<column name="CODIGO_MACROPROCESO" />
<column name="CODIGO_PROCESO" />
</key-many-to-one>
</composite-id>
<property name="nombre" column="NOMBRE" />
</class>
And here is the log:
Code:
12:54:10,981 DEBUG SessionImpl:84 - opened session at timestamp: 12597548509
12:54:10,981 DEBUG JDBCTransaction:84 - begin
12:54:10,981 DEBUG ConnectionManager:84 - opening JDBC connection
12:54:10,981 DEBUG JDBCTransaction:84 - current autocommit status: false
12:54:13,809 DEBUG AbstractSaveEventListener:84 - generated identifier: component[codigoTipoEntregable,proceso]{proceso=com.endesa.mproweb.crscrscrs.negocio.entidad.Proceso#component[codigoProceso,macroproceso]{macroproceso=com.endesa.mproweb.crscrscrs.negocio.entidad.Macroproceso#DIM, codigoProceso=DIS}, codigoTipoEntregable=210}, using strategy: org.hibernate.id.Assigned
12:54:15,731 DEBUG JDBCTransaction:84 - commit
12:54:15,731 DEBUG AbstractFlushingEventListener:84 - processing flush-time cascades
12:54:15,731 DEBUG AbstractFlushingEventListener:84 - dirty checking collections
12:54:15,731 DEBUG AbstractFlushingEventListener:84 - Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects
12:54:15,731 DEBUG AbstractFlushingEventListener:84 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
12:54:15,731 DEBUG Printer:84 - listing entities:
12:54:15,762 DEBUG Printer:84 - com.endesa.mproweb.crscrscrs.negocio.entidad.TipoEntregable{nombre=Diseño Funcional y de Usuario, id=component[codigoTipoEntregable,proceso]{proceso=com.endesa.mproweb.crscrscrs.negocio.entidad.Proceso#component[codigoProceso,macroproceso]{macroproceso=com.endesa.mproweb.crscrscrs.negocio.entidad.Macroproceso#DIM, codigoProceso=DIS}, codigoTipoEntregable=210}}
12:54:15,762 DEBUG AbstractBatcher:84 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
12:54:15,762 DEBUG SQL:84 - insert into TIPOS_ENTREGABLE (NOMBRE, CODIGO, CODIGO_MACROPROCESO, CODIGO_PROCESO) values (?, ?, ?, ?)
Hibernate: insert into TIPOS_ENTREGABLE (NOMBRE, CODIGO, CODIGO_MACROPROCESO, CODIGO_PROCESO) values (?, ?, ?, ?)
12:54:15,778 DEBUG AbstractBatcher:84 - Executing batch size: 1
12:54:15,778 DEBUG AbstractBatcher:84 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
12:54:15,794 DEBUG JDBCExceptionReporter:89 - Could not execute JDBC batch update [insert into TIPOS_ENTREGABLE (NOMBRE, CODIGO, CODIGO_MACROPROCESO, CODIGO_PROCESO) values (?, ?, ?, ?)]
java.sql.BatchUpdateException: failed batch
at org.hsqldb.jdbc.jdbcStatement.executeBatch(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.executeBatch(Unknown Source)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.endesa.mproweb.test.TestMain.createAndStoreTipoEntregable(TestMain.java:127)
at com.endesa.mproweb.test.TestMain.main(TestMain.java:33)
12:54:15,794 WARN JDBCExceptionReporter:104 - SQL Error: 0, SQLState: null
12:54:15,794 ERROR JDBCExceptionReporter:114 - failed batch
12:54:15,794 ERROR AbstractFlushingEventListener:119 - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.endesa.mproweb.test.TestMain.createAndStoreTipoEntregable(TestMain.java:127)
at com.endesa.mproweb.test.TestMain.main(TestMain.java:33)
Caused by: java.sql.BatchUpdateException: failed batch
at org.hsqldb.jdbc.jdbcStatement.executeBatch(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.executeBatch(Unknown Source)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
... 9 more
Thank you very much,
Pepe Martínez