Hi. I'm having a problem when trying to save a object with childs, referencing the parent (Bidirectional Association).
This is the exception:
Code:
[IBM][CLI Driver][DB2/NT] SQL0530N The insert or update value of the FOREIGN KEY "INTRANET.WF_EVENTOSWORKFLOW.FK_ESTADO_ORIGEN" is not equal to any value of the parent key of the parent table. SQLSTATE=23503
The stack trace in debug verbose is:
Code:
13:34:05 DEBUG impl.SessionImpl : opened session
13:34:05 DEBUG transaction.JDBCTransaction : begin
13:34:05 DEBUG transaction.JDBCTransaction : current autocommit status:false
13:34:05 DEBUG impl.SessionImpl : generated identifier: 0
13:34:05 DEBUG impl.SessionImpl : saving [cl.nectia.workflow.Malla#0]
13:34:05 DEBUG engine.Cascades : processing cascades for: cl.nectia.workflow.Malla
13:34:05 DEBUG engine.Cascades : cascading to saveOrUpdate()
13:34:05 DEBUG engine.Cascades : id unsaved-value strategy NULL
13:34:05 DEBUG impl.SessionImpl : saveOrUpdate() previously saved instance with id: wf_10
13:34:05 DEBUG impl.SessionImpl : updating [cl.nectia.workflow.EstadoWorkflow#wf_10]
13:34:05 DEBUG impl.SessionImpl : collection dereferenced while transient [cl.nectia.workflow.EstadoWorkflow.eventos#wf_10]
13:34:05 DEBUG engine.Cascades : processing cascades for: cl.nectia.workflow.EstadoWorkflow
13:34:05 DEBUG engine.Cascades : cascading to collection: cl.nectia.workflow.EstadoWorkflow.eventos
13:34:05 DEBUG engine.Cascades : cascading to saveOrUpdate()
13:34:05 DEBUG engine.Cascades : id unsaved-value: 0
13:34:05 DEBUG impl.SessionImpl : saveOrUpdate() unsaved instance
13:34:05 DEBUG impl.SessionImpl : saving [cl.nectia.workflow.EventoWorkflow#<null>]
13:34:05 DEBUG impl.SessionImpl : executing insertions
13:34:05 DEBUG engine.Cascades : id unsaved-value strategy NULL
13:34:05 DEBUG persister.EntityPersister : Inserting entity: cl.nectia.workflow.EventoWorkflow (native id)
13:34:05 DEBUG impl.BatcherImpl : about to open: 0 open PreparedStatements, 0 open ResultSets
13:34:05 DEBUG hibernate.SQL : insert into INTRANET.WF_EVENTOSWORKFLOW (ESTADO_ORIGEN, ESTADO_DESTINO, NAME, ID) values (?, ?, ?, default)
Hibernate: insert into INTRANET.WF_EVENTOSWORKFLOW (ESTADO_ORIGEN, ESTADO_DESTINO, NAME, ID) values (?, ?, ?, default)
13:34:05 DEBUG impl.BatcherImpl : preparing statement
13:34:05 DEBUG persister.EntityPersister : Dehydrating entity: [cl.nectia.workflow.EventoWorkflow#<null>]
13:34:05 DEBUG type.StringType : binding 'wf_10' to parameter: 1
13:34:05 DEBUG engine.Cascades : id unsaved-value strategy NULL
13:34:05 DEBUG type.StringType : binding 'wf_20' to parameter: 2
13:34:05 DEBUG type.StringType : binding 'autorizar' to parameter: 3
13:34:05 DEBUG util.JDBCExceptionReporter : SQL Exception
COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/NT] SQL0530N The insert or update value of the FOREIGN KEY "INTRANET.WF_EVENTOSWORKFLOW.FK_ESTADO_ORIGEN" is not equal to any value of the parent key of the parent table. SQLSTATE=23503
The mapping for the referenced classes is:
Code:
<class name="cl.nectia.workflow.EstadoWorkflow" table="WF_ESTADOS">
<id name="id" column="ID" unsaved-value="null">
<generator class="assigned"/>
</id>
<property name="descripcion" column="DESCRIPCION"/>
<property name="tmax" column="TMAX"/>
<bag name="eventos" table="WF_EVENTOSWORKFLOW" inverse="true" cascade="all" lazy="true" >
<key column="CONTENEDOR" foreign-key="FK_ESTADO_WORKFLOW"/>
<one-to-many class="cl.nectia.workflow.EventoWorkflow" />
</bag>
</class>
<class name="cl.nectia.workflow.EventoWorkflow" table="WF_EVENTOSWORKFLOW">
<id name="id" column="ID" unsaved-value="0">
<generator class="native"/>
</id>
<many-to-one name="estadoOrigen" column="ESTADO_ORIGEN" foreign-key="FK_ESTADO_ORIGEN"/>
<many-to-one name="estadoDestino" column="ESTADO_DESTINO" foreign-key="FK_ESTADO_DESTINO"/>
<property name="name" column="NAME"/>
</class>
The DDL was created with schema export:
Code:
create table WF_EVENTOSWORKFLOW (
ID BIGINT not null generated by default as identity,
ESTADO_ORIGEN VARCHAR(255),
ESTADO_DESTINO VARCHAR(255),
NAME VARCHAR(255),
CONTENEDOR VARCHAR(255),
primary key (ID)
)
create table WF_ESTADOS (
ID VARCHAR(255) not null,
DESCRIPCION VARCHAR(255),
TMAX BIGINT,
MALLA BIGINT,
primary key (ID)
)
alter table WF_EVENTOSWORKFLOW add constraint FK_ESTADO_DESTINO foreign key (ESTADO_DESTINO) references WF_ESTADOS
alter table WF_EVENTOSWORKFLOW add constraint FK_ESTADO_ORIGEN foreign key (ESTADO_ORIGEN) references WF_ESTADOS
alter table WF_ESTADOS add constraint FK_MALLA foreign key (MALLA) references WF_MALLAS
This are the properties of the EstadoWorkflow class:
Code:
public class EstadoWorkflow {
private String id;
private String descripcion;
private String adicional;
private long tmax;
private long alerta;
private List eventos = new ArrayList();
...
and this are the EventoWorkflow ones:
Code:
public class EventoWorkflow {
private long id;
private EstadoWorkflow estadoOrigen;
private EstadoWorkflow estadoDestino;
private String name;
...
I read on the hibernate manual about
Bidirectional Associations but I'm not sure how to implement it in this case.
Any help would be very appreciated!
Thank you very much!!!