-->
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.  [ 9 posts ] 
Author Message
 Post subject: Foreign Key Violation in Parent Childs association
PostPosted: Thu May 20, 2004 1:44 pm 
Beginner
Beginner

Joined: Mon Mar 08, 2004 6:09 pm
Posts: 20
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!!!


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 24, 2004 10:27 am 
Beginner
Beginner

Joined: Mon Mar 08, 2004 6:09 pm
Posts: 20
Plase don't forget this topic... or, Doesn't hibernate support this kind of association??

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 24, 2004 11:53 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
show java code

of course hibernate supports this....

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 24, 2004 12:12 pm 
Beginner
Beginner

Joined: Mon Mar 08, 2004 6:09 pm
Posts: 20
The java code is showed above, in the first post. The code to save the objects it's simple... create objects, and session.save().

Do you need the detailed code??

I think it's just a mapping problem.

Thank you!


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 24, 2004 2:32 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
excuse me i can't see any new instanciation or save call, but i might be too busy

i'll check again tomorrow morning!

follow these steps:
http://www.hibernate.org/155.html

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 24, 2004 3:21 pm 
Beginner
Beginner

Joined: Mon Mar 08, 2004 6:09 pm
Posts: 20
Thanks for the link, but it only has the simple example of inverse=true. As you can see in my classes definition, the case is a little bit complex. I'm posting all the code now:


This is the Malla class:
Code:
public class Malla {

   private long id;
   private List estados = new ArrayList();
   private EstadoWorkflow estadoInicial;
   private String descripcion;

   public Malla() {
      super();
   }

   public Malla(List estados, EstadoWorkflow estadoInicial, String descripcion) {
      this.setEstados(estados);
      this.setEstadoInicial(estadoInicial);
      this.setDescripcion(descripcion);
   }

public void addEstado(EstadoWorkflow estado) {
      this.estados.add(estado);
   }
... (getters and setters)


The EstadoWorkflow class:
Code:
private String id;
   private String descripcion;
   private String adicional;
   private long tmax;   
   private long alerta;
   
   private List eventos = new ArrayList();

   public EstadoWorkflow() {
      super();
   }

   public EstadoWorkflow(String id, String descripcion, long tMax, List eventos) {
      this.setId(id);
      this.setDescripcion(descripcion);
      this.setTmax(tMax);
      this.setEventos(eventos);
   }

   public void addEstadoSiguiente(String eventName, EstadoWorkflow destino) {
      this.getEventos().add(new EventoWorkflow(eventName, this, destino));
   }
.... (getters and setters)


And the EventoWorkflow class:
Code:
public class EventoWorkflow {

   private long id;
   private EstadoWorkflow estadoOrigen;
   private EstadoWorkflow estadoDestino;
   private String name;
   
   public EventoWorkflow() {
      super();
   }

   public EventoWorkflow(String name, EstadoWorkflow estadoOrigen, EstadoWorkflow estadoDestino) {
      super();
      this.name = name;
      this.estadoOrigen = estadoOrigen;
      this.estadoDestino = estadoDestino;
   }

   public EstadoWorkflow getEstadoDestino() {
      return estadoDestino;
   }

   public EstadoWorkflow getEstadoOrigen() {
      return estadoOrigen;
   }

   public long getId() {
      return id;
   }

   public String getName() {
      return name;
   }

   public void setEstadoDestino(EstadoWorkflow estadoDestino) {
      this.estadoDestino = estadoDestino;
   }

   public void setEstadoOrigen(EstadoWorkflow estadoOrigen) {
      this.estadoOrigen = estadoOrigen;
   }

   public void setId(long id) {
      this.id = id;
   }

   public void setName(String name) {
      this.name = name;
   }

}


Here is a test method to fill my workflow states and events:
[code]public void testWF(){
int[] codigos = new int[] { 10, 20, 30 };
String[] nombres = new String[] { "Ingresado", "Autorizado", "Publicado" };
HashMap estados = new HashMap();
Malla malla = new Malla();

for (int i = 0; i < codigos.length; i++) {
EstadoWorkflow estado = new EstadoWorkflow();
estado.setId("wf_" + Integer.toString(codigos[i]));
estado.setDescripcion(nombres[i]);
estado.setTmax(1);
malla.addEstado(estado);
estados.put("wf_" + Integer.toString(codigos[i]), estado);
}

malla.setDescripcion("Estados publicaci


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 25, 2004 10:57 am 
Beginner
Beginner

Joined: Mon Mar 08, 2004 6:09 pm
Posts: 20
Any help with this topic would be very appreciated

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 27, 2004 10:13 am 
Beginner
Beginner

Joined: Mon Mar 08, 2004 6:09 pm
Posts: 20
Any news???


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 27, 2004 10:15 am 
Beginner
Beginner

Joined: Mon Mar 08, 2004 6:09 pm
Posts: 20
Any news???


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

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.