-->
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.  [ 11 posts ] 
Author Message
 Post subject: URGENT! just can't get this working
PostPosted: Sun Dec 21, 2003 9:25 am 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
Please help me!
I've been with this for a week and can't get it working.
It keeps giving me:

Code:
WARN : SQL Error: 0, SQLState: null
ERROR: ERROR:  op_cont_inicio_op_turnos_fk referential integrity violation - key referenced from op_controlo_inicio not found in op_turnos

ERROR: could not insert: [pt.comseal.arsol.vo.OpControloInicio#1]
java.sql.SQLException: ERROR:  op_cont_inicio_op_turnos_fk referential integrity violation - key referenced from op_controlo_inicio not found in op_turnos
( ... )


Don't know why!? I've seen every file top to bottom and just can't find the problem.

Can someone please tell me what's wrong with the code?


----------
DDL's
----------
Code:
CREATE TABLE OP_TURNOS (
       op_fk INT8 NOT NULL
     , turno_fk SMALLINT NOT NULL
     , data_turno INT8 NOT NULL
     , user_id CHAR(10) NOT NULL
     , PRIMARY KEY (op_fk, turno_fk, data_turno)
     , CONSTRAINT op_turnos_op_fk FOREIGN KEY (op_fk)
                  REFERENCES OP (id)
     , CONSTRAINT op_turnos_turnos_fk FOREIGN KEY (turno_fk)
                  REFERENCES TURNOS (id)
);

CREATE TABLE OP_CONTROLO_INICIO (
       id INT8 NOT NULL
     , op_fk INT8 NOT NULL
     , turno_fk SMALLINT NOT NULL
     , data_turno_fk INT8 NOT NULL
     , hora_inicio TIME(10) NOT NULL
     , user_id CHAR(10) NOT NULL
     , PRIMARY KEY (id)
     , CONSTRAINT op_controlo_inicio_unique UNIQUE (op_fk, turno_fk, data_turno_fk, hora_inicio)
     , CONSTRAINT op_cont_inicio_op_turnos_fk FOREIGN KEY (op_fk, turno_fk, data_turno_fk)
                  REFERENCES OP_TURNOS (op_fk, turno_fk, data_turno)
);


------------------------------------------------------
Mapping files (generated with Middlegen R3)
------------------------------------------------------

OpTurno
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
   
<hibernate-mapping>
<!--
    Created by Middlegen Hibernate plugin

    http://boss.bekk.no/boss/middlegen/
    http://hibernate.sourceforge.net/
-->

<class
    name="vo.OpTurno"
    table="op_turnos"
>

    <composite-id name="comp_id" class="vo.OpTurnoPK">
        <key-property
            name="dataTurno"
            column="data_turno"
            type="long"
            length="8"
        />
        <!-- bi-directional many-to-one association to Turno -->
        <key-many-to-one
           name="turno"
           class="vo.Turno"
       >
           <column name="turno_fk" />
       </key-many-to-one>
        <!-- bi-directional many-to-one association to Op -->
        <key-many-to-one
           name="op"
           class="vo.Op"
       >
           <column name="op_fk" />
       </key-many-to-one>
    </composite-id>   

    <property
        name="userId"
        type="java.lang.String"
        column="user_id"
        not-null="true"
        length="10"
    />

    <!-- associations -->
    <!-- bi-directional one-to-many association to OpControloInicio -->
    <set
        name="opControloInicios"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="op_fk" />
            <column name="turno_fk" />
            <column name="data_turno_fk" />
        </key>
        <one-to-many
            class="vo.OpControloInicio"
        />
    </set>

</class>
</hibernate-mapping>


OpControloInicio
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
   
<hibernate-mapping>
<!--
    Created by Middlegen Hibernate plugin

    http://boss.bekk.no/boss/middlegen/
    http://hibernate.sourceforge.net/
-->

<class
    name="vo.OpControloInicio"
    table="op_controlo_inicio"
>

    <id
        name="id"
        type="long"
        column="id"
    >
        <generator class="increment" />
    </id>

    <property
        name="horaInicio"
        type="java.sql.Time"
        column="hora_inicio"
        not-null="true"
        length="8"
    />
    <property
        name="userId"
        type="java.lang.String"
        column="user_id"
        not-null="true"
        length="10"
    />

    <!-- associations -->
    <!-- bi-directional many-to-one association to OpTurno -->
    <many-to-one
        name="opTurno"
        class="vo.OpTurno"
        not-null="true"
    >
        <column name="op_fk" />
        <column name="turno_fk" />
        <column name="data_turno_fk" />
    </many-to-one>

</class>
</hibernate-mapping>


---------
CODE
---------

Code:
SessionFactory sessionFactory = HibernateFactory.createFactory();   
session = sessionFactory.openSession();
transaction = session.beginTransaction();

OpTurnoPK op_turno_pk = new OpTurnoPK();
op_turno_pk.setDataTurno(new Long(20122003).longValue());
      
Op op = new Op();
op.setId(new Long(1));
op_turno_pk.setOp(op);
         
Turno turno = new Turno();
turno.setId(new Integer(1).shortValue());
op_turno_pk.setTurno(turno);
      
OpTurno op_turno = new OpTurno();
op_turno.setComp_id(op_turno_pk);
op_turno.setUserId(user_id);

OpControloInicio op_controlo_inicio = new OpControloInicio();
op_controlo_inicio.setHoraInicio(java.sql.Time.valueOf(new SimpleDateFormat("HH:mm:ss").format(new java.sql.Time((new Date(System.currentTimeMillis()).getTime()))));
op_controlo_inicio.setOpTurno(op_turno);
op_controlo_inicio.setUserId(user_id);

HashSet op_cont_inis = new HashSet();
op_cont_inis.add(op_controlo_inicio);
op_turno.setOpControloInicios(op_cont_inis);

session.save(op_turno);
transaction.commit();
session.close();


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 21, 2003 10:07 am 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
You either do not have Op with id=1 or Turno with id=1 in the database.

If you need your newly created Op & Turno be saved to database - just save them.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 21, 2003 10:31 am 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
dimas wrote:
You either do not have Op with id=1 or Turno with id=1 in the database.

If you need your newly created Op & Turno be saved to database - just save them.


They exist in the database.
I'm printing all the properties right before the "session.save".

Any ideas please?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 21, 2003 10:33 am 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
dimas wrote:
You either do not have Op with id=1 or Turno with id=1 in the database.

If you need your newly created Op & Turno be saved to database - just save them.


They exist in the database.
I'm printing all the properties right before the "session.save".

Any ideas please?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 21, 2003 10:45 am 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
Quote:
They exist in the database.
I'm printing all the properties right before the "session.save".


Properties of what? You can print properties of youa newly created transient objects but these objects do not persisted to the database yet. By the way, I see no any printing in your code.

Please paste debug log here.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 21, 2003 11:42 am 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
dimas wrote:
Quote:
They exist in the database.
I'm printing all the properties right before the "session.save".


Properties of what? You can print properties of youa newly created transient objects but these objects do not persisted to the database yet. By the way, I see no any printing in your code.

Please paste debug log here.


Here's my debug log.

Code:
Hibernate: select opcontrolo0_.op_fk as op_fk10_, opcontrolo0_.ultima_paragem_fk as ultima_p2_10_, opcontrolo0_.sector as sector10_, opcontrolo0_.referencia as referencia10_, opcontrolo0_.inicio_ordem_prod as inicio_o5_10_, opcontrolo0_.fim_ordem_prod as fim_orde6_10_, opcontrolo0_.inicio_mont_molde as inicio_m7_10_, opcontrolo0_.fim_mont_molde as fim_mont8_10_, opcontrolo0_.inicio_mont_ferramenta as inicio_m9_10_, opcontrolo0_.fim_mont_ferramenta as fim_mon10_10_, opcontrolo0_.inicio_desmont_molde as inicio_11_10_, opcontrolo0_.fim_desmont_molde as fim_des12_10_, opcontrolo0_.inicio_desmont_ferramenta as inicio_13_10_, opcontrolo0_.fim_desmont_ferramenta as fim_des14_10_, opcontrolo0_.inicio_producao as inicio_15_10_, opcontrolo0_.fim_producao as fim_pro16_10_, opcontrolo0_.dthr_aprovacao_prod as dthr_ap17_10_, opcontrolo0_.dthr_desaprovacao_prod as dthr_de18_10_, opcontrolo0_.qtd_rej_cont_vol as qtd_rej19_10_, opcontrolo0_.qtd_rej_mon_med as qtd_rej20_10_, opcontrolo0_.qtd_produzida as qtd_pro21_10_, opcontrolo0_.user_id as user_id10_, opcontrolo0_.dt_hr as dt_hr10_, opcontrolo0_.equip_prod_fk as equip_p24_10_, opcontrolo0_.produto_fk as produto_fk10_, op1_.id as id0_, op1_.responsavel_fk as responsa2_0_, op1_.quantidade as quantidade0_, op1_.data_inicio as data_ini4_0_, op1_.data_fim as data_fim0_, op1_.user_id as user_id0_, op1_.dt_hr as dt_hr0_, op1_.estado_op_fk as estado_o8_0_, op1_.produto_fk as produto_fk0_, estadoop2_.id as id1_, estadoop2_.descricao as descricao1_, estadoop2_.user_id as user_id1_, estadoop2_.dt_hr as dt_hr1_, produto3_.id as id2_, produto3_.doc_esq_montagem_fk as doc_esq_2_2_, produto3_.doc_oper_montagem_fk as doc_oper3_2_, produto3_.referencia as referencia2_, produto3_.designacao as designacao2_, produto3_.descricao as descricao2_, produto3_.norma as norma2_, produto3_.tubo_pvc as tubo_pvc2_, produto3_.tipo_tubo_pvc as tipo_tub9_2_, produto3_.serie_tubo_pvc as serie_t10_2_, produto3_.classe_pressao_tubo_pvc as classe_11_2_, produto3_.tipo_aborcagem as tipo_ab12_2_, produto3_.esteira as esteira2_, produto3_.tipo_perfil_esteira as tipo_pe14_2_, produto3_.codigo_postico as codigo_15_2_, produto3_.pecas as pecas2_, produto3_.diametro as diametro2_, produto3_.tipo_aborcagem_uni as tipo_ab18_2_, produto3_.tipo_aborcagem_din as tipo_ab19_2_, produto3_.graus4530 as graus45302_, produto3_.graus8730 as graus87302_, produto3_.tipo_etiquetagem as tipo_et22_2_, produto3_.obs as obs2_, produto3_.desc_inst_preparacao as desc_in24_2_, produto3_.imagem_inst_preparacao as imagem_25_2_, produto3_.tipo_tubo_origem as tipo_tu26_2_, produto3_.comprimento_tubo_origem as comprim27_2_, produto3_.desc_inst_soldadura as desc_in28_2_, produto3_.imagem_inst_soldadura as imagem_29_2_, produto3_.desc_inst_montagem as desc_in30_2_, produto3_.imagem_inst_montagem as imagem_31_2_, produto3_.estado as estado2_, produto3_.user_id as user_id2_, produto3_.dt_hr as dt_hr2_, produto3_.mistura_fk as mistura_fk2_, produto3_.embalagem_fk as embalag36_2_, produto3_.tipo_produto_fk as tipo_pr37_2_, mistura4_.id as id3_, mistura4_.referencia as referencia3_, mistura4_.designacao as designacao3_, mistura4_.quantidade as quantidade3_, mistura4_.temper_pan_quente as temper_p5_3_, mistura4_.temper_pan_fria as temper_p6_3_, mistura4_.tempo_pan_quente as tempo_pa7_3_, mistura4_.tempo_pan_fria as tempo_pa8_3_, mistura4_.estado as estado3_, mistura4_.user_id as user_id3_, mistura4_.dt_hr as dt_hr3_, mistura4_.formula_fk as formula_fk3_, formula5_.id as id4_, formula5_.referencia as referencia4_, formula5_.designacao as designacao4_, formula5_.seccao as seccao4_, formula5_.estado as estado4_, formula5_.user_id as user_id4_, formula5_.dt_hr as dt_hr4_, embalagem6_.id as id5_, embalagem6_.referencia as referencia5_, embalagem6_.descricao as descricao5_, embalagem6_.user_id as user_id5_, embalagem6_.dt_hr as dt_hr5_, tipoprodut7_.id as id6_, tipoprodut7_.descricao as descricao6_, tipoprodut7_.user_id as user_id6_, tipoprodut7_.dt_hr as dt_hr6_, equipprod8_.id as id7_, equipprod8_.referencia as referencia7_, equipprod8_.designacao as designacao7_, equipprod8_.sector as sector7_, equipprod8_.descricao as descricao7_, equipprod8_.ano_fabrico as ano_fabr6_7_, equipprod8_.ano_compra as ano_compra7_, equipprod8_.fabricante as fabricante7_, equipprod8_.doc_cond_process as doc_cond9_7_, equipprod8_.estado as estado7_, equipprod8_.linha as linha7_, equipprod8_.dt_prox_man_prev as dt_prox12_7_, equipprod8_.user_id as user_id7_, equipprod8_.dt_hr as dt_hr7_, equipprod8_.equip_prod_tipo_fk as equip_p15_7_, equipprod8_.equip_categoria_fk as equip_c16_7_, equipprodt9_.id as id8_, equipprodt9_.descricao as descricao8_, equipprodt9_.user_id as user_id8_, equipprodt9_.dt_hr as dt_hr8_, equipprodc10_.id as id9_, equipprodc10_.descricao as descricao9_, equipprodc10_.user_id as user_id9_, equipprodc10_.dt_hr as dt_hr9_ from op_controlo_sq058_9 opcontrolo0_ left outer join op op1_ on opcontrolo0_.op_fk=op1_.id left outer join estado_op estadoop2_ on op1_.estado_op_fk=estadoop2_.id left outer join produto produto3_ on op1_.produto_fk=produto3_.id left outer join mistura mistura4_ on produto3_.mistura_fk=mistura4_.id left outer join formula formula5_ on mistura4_.formula_fk=formula5_.id left outer join embalagem embalagem6_ on produto3_.embalagem_fk=embalagem6_.id left outer join tipo_produto tipoprodut7_ on produto3_.tipo_produto_fk=tipoprodut7_.id left outer join equip_prod equipprod8_ on opcontrolo0_.equip_prod_fk=equipprod8_.id left outer join equip_prod_tipo equipprodt9_ on equipprod8_.equip_prod_tipo_fk=equipprodt9_.id left outer join equip_prod_categoria equipprodc10_ on equipprod8_.equip_categoria_fk=equipprodc10_.id where opcontrolo0_.op_fk=?
MY_PRINT_OP: 1
MY_PRINT_TURNO: 1
MY_PRINT_DATA_TURNO: 20122003
MY_PRINT_HORA_INICIO: 15:40:21
Hibernate: select opturno0_.data_turno as data_turno4_, opturno0_.turno_fk as turno_fk4_, opturno0_.op_fk as op_fk4_, opturno0_.user_id as user_id4_, opturno0_.dt_hr as dt_hr4_, controlovo1_.op_fk as op_fk0_, controlovo1_.turno_fk as turno_fk0_, controlovo1_.data_turno_fk as data_tur3_0_, controlovo1_.produto_fk as produto_fk0_, controlovo1_.equip_prod_fk as equip_pr5_0_, controlovo1_.referencia as referencia0_, controlovo1_.num_op as num_op0_, controlovo1_.norma as norma0_, controlovo1_.datahora_inicio_op as datahora9_0_, controlovo1_.datahora_fim_op as datahor10_0_, controlovo1_.comprimento_i as comprim11_0_, controlovo1_.comprimento_f as comprim12_0_, controlovo1_.diam_exter_i as diam_ex13_0_, controlovo1_.diam_exter_f as diam_ex14_0_, controlovo1_.espessura_i as espessu15_0_, controlovo1_.espessura_f as espessu16_0_, controlovo1_.ovalizacao as ovalizacao0_, controlovo1_.diam_int_dint_i as diam_in18_0_, controlovo1_.diam_int_dint_f as diam_in19_0_, controlovo1_.chanfro_a as chanfro_a0_, controlovo1_.chanfro_b as chanfro_b0_, controlovo1_.aborcagem_c as aborcag22_0_, controlovo1_.aborcagem_m as aborcag23_0_, controlovo1_.aneld_i as aneld_i0_, controlovo1_.aneld_f as aneld_f0_, controlovo1_.func_i as func_i0_, controlovo1_.func_f as func_f0_, controlovo1_.data_verificacao as data_ve28_0_, controlovo1_.user_id as user_id0_, controlovo1_.dt_hr as dt_hr0_, opcontrolo2_.op_fk as op_fk1_, opcontrolo2_.turno_fk as turno_fk1_, opcontrolo2_.data_turno_fk as data_tur3_1_, opcontrolo2_.hora_monitorizacao as hora_mon4_1_, opcontrolo2_.reaccao as reaccao1_, opcontrolo2_.user_id as user_id1_, opcontrolo2_.dt_hr as dt_hr1_, opcontrolo2_.tipo_problema_fk as tipo_pro8_1_, tipoproble3_.id as id2_, tipoproble3_.descricao as descricao2_, tipoproble3_.user_id as user_id2_, tipoproble3_.dt_hr as dt_hr2_, opcontrolo4_.op_fk as op_fk3_, opcontrolo4_.turno_fk as turno_fk3_, opcontrolo4_.data_turno_fk as data_tur3_3_, opcontrolo4_.total_producao as total_pr4_3_, opcontrolo4_.user_id as user_id3_, opcontrolo4_.dt_hr as dt_hr3_ from op_turnos opturno0_ left outer join controlo_volante controlovo1_ on opturno0_.data_turno=controlovo1_.op_fk and opturno0_.turno_fk=controlovo1_.turno_fk and opturno0_.op_fk=controlovo1_.data_turno_fk left outer join op_controlo_monotorizacao opcontrolo2_ on opturno0_.data_turno=opcontrolo2_.op_fk and opturno0_.turno_fk=opcontrolo2_.turno_fk and opturno0_.op_fk=opcontrolo2_.data_turno_fk left outer join tipo_problema tipoproble3_ on opcontrolo2_.tipo_problema_fk=tipoproble3_.id left outer join op_controlo_producao opcontrolo4_ on opturno0_.data_turno=opcontrolo4_.op_fk and opturno0_.turno_fk=opcontrolo4_.turno_fk and opturno0_.op_fk=opcontrolo4_.data_turno_fk where opturno0_.data_turno=? and opturno0_.turno_fk=? and opturno0_.op_fk=?
Hibernate: insert into op_turnos (user_id, dt_hr, data_turno, turno_fk, op_fk) values (?, ?, ?, ?, ?)
Hibernate: insert into op_controlo_inicio (hora_inicio, qtd_produzida, user_id, dt_hr, op_fk, turno_fk, data_turno_fk, id) values (?, ?, ?, ?, ?, ?, ?, ?)
WARN : SQL Error: 0, SQLState: null
ERROR: ERROR:  op_cont_inicio_op_turnos_fk referential integrity violation - key referenced from op_controlo_inicio not found in op_turnos

ERROR: could not insert: [pt.comseal.arsol.vo.OpControloInicio#1]
java.sql.SQLException: ERROR:  op_cont_inicio_op_turnos_fk referential integrity violation - key referenced from op_controlo_inicio not found in op_turnos

   at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:131)
   at org.postgresql.jdbc1.AbstractJdbc1Connection.ExecSQL(AbstractJdbc1Connection.java:505)
   at org.postgresql.jdbc1.AbstractJdbc1Statement.execute(AbstractJdbc1Statement.java:320)
   at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:48)
   at org.postgresql.jdbc1.AbstractJdbc1Statement.executeUpdate(AbstractJdbc1Statement.java:197)
   at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:469)
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:443)
   at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:29)
   at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2308)
   at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2261)
   at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2187)
   at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
   at pt.comseal.arsol.bo.controlo.ControloBO.registarInicioProducao(ControloBO.java:404)
   at pt.comseal.arsol.bo.controlo.Teste.main(Teste.java:155)
ERROR: Could not synchronize database state with session
net.sf.hibernate.JDBCException: could not insert: [pt.comseal.arsol.vo.OpControloInicio#1]
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:479)
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:443)
   at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:29)
   at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2308)
   at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2261)
   at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2187)
   at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
   at pt.comseal.arsol.bo.controlo.ControloBO.registarInicioProducao(ControloBO.java:404)
   at pt.comseal.arsol.bo.controlo.Teste.main(Teste.java:155)
Caused by: java.sql.SQLException: ERROR:  op_cont_inicio_op_turnos_fk referential integrity violation - key referenced from op_controlo_inicio not found in op_turnos

   at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:131)
   at org.postgresql.jdbc1.AbstractJdbc1Connection.ExecSQL(AbstractJdbc1Connection.java:505)
   at org.postgresql.jdbc1.AbstractJdbc1Statement.execute(AbstractJdbc1Statement.java:320)
   at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:48)
   at org.postgresql.jdbc1.AbstractJdbc1Statement.executeUpdate(AbstractJdbc1Statement.java:197)
   at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:469)
   ... 8 more
net.sf.hibernate.JDBCException: could not insert: [pt.comseal.arsol.vo.OpControloInicio#1]
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:479)
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:443)
   at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:29)
   at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2308)
   at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2261)
   at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2187)
   at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
   at pt.comseal.arsol.bo.controlo.ControloBO.registarInicioProducao(ControloBO.java:404)
   at pt.comseal.arsol.bo.controlo.Teste.main(Teste.java:155)
Caused by: java.sql.SQLException: ERROR:  op_cont_inicio_op_turnos_fk referential integrity violation - key referenced from op_controlo_inicio not found in op_turnos

   at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:131)
   at org.postgresql.jdbc1.AbstractJdbc1Connection.ExecSQL(AbstractJdbc1Connection.java:505)
   at org.postgresql.jdbc1.AbstractJdbc1Statement.execute(AbstractJdbc1Statement.java:320)
   at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:48)
   at org.postgresql.jdbc1.AbstractJdbc1Statement.executeUpdate(AbstractJdbc1Statement.java:197)
   at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:469)
   ... 8 more


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 21, 2003 11:46 am 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
dimas wrote:
Quote:
They exist in the database.
I'm printing all the properties right before the "session.save".


Properties of what? You can print properties of youa newly created transient objects but these objects do not persisted to the database yet. By the way, I see no any printing in your code.

Please paste debug log here.


NOTE:

As you can see in the select's generated by Hibernate, there are references to other classes that aren't in the "OpTurno" mapping file. I took them out on purpose to simplify the reading.
And here are the "prints" I'm making before the "session.save(op_turno)":

System.out.println("MY_PRINT_OP: " + op_controlo_inicio.getOpTurno().getComp_id().getOp().getId());
System.out.println("MY_PRINT_TURNO: " + op_controlo_inicio.getOpTurno().getComp_id().getTurno().getId());
System.out.println("MY_PRINT_DATA_TURNO: " + op_controlo_inicio.getOpTurno().getComp_id().getDataTurno());
System.out.println("MY_PRINT_HORA_INICIO: " + op_controlo_inicio.getHoraInicio());

I omitted them to simplify reading.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 21, 2003 12:47 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
Quote:
And here are the "prints" I'm making before the "session.save(op_turno)":



Look, these prints do not guaratee anything! Yo are printing properties of the object you just set yourself! Are you sure there are alreayd Op & Turno with ID=1 in the database?

Try to run plain SQL and see what it returns

select * from OP_TURNOS where op_fk=1 and turno_fk=1 and data_turno=20122003

I bet you'll get 0 rows.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 21, 2003 12:49 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
Oops, sorry.
Ignore my last post


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 21, 2003 1:06 pm 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
dimas wrote:
Oops, sorry.
Ignore my last post


I know it will return 0 rows. That's why I'm trying to "session.save(op_turno)".
I already have a row with id=1 in OP and a row with id=1 in TURNO. I've checked.

I just want to insert a row in OP_TURNOS with "op_fk=1", "turno_fk=1" and "data_turno=20122003", and then insert a row in OP_CONTROLO_INICIO (cascaded).

OP_CONTROLO_INICIO is a "set" of OP_TURNOS. I've put a cascade="save-update" like:

[code]
( ... )
<set
name="opControloInicios"
lazy="true"
inverse="true"
cascade="save-update"
>
<key>
<column name="op_fk" />
<column name="turno_fk" />
<column name="data_turno_fk" />
</key>
<one-to-many
class="pt.comseal.arsol.vo.OpControloInicio"
/>
</set>
( ... )
[/b]

But still no success.

Any idea?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 21, 2003 1:41 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
I would enable logging of statement parameters to see what data you are inserting actually. There were postings describing how to do that - http://forum.hibernate.org/viewtopic.ph ... highlight=


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 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.