-->
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.  [ 1 post ] 
Author Message
 Post subject: Can t save the child after saving the Parent !FK Constraint
PostPosted: Fri Nov 23, 2012 9:06 am 
Newbie

Joined: Fri Nov 23, 2012 8:26 am
Posts: 2
Bonjour,


J'ai un problème de ORA-02291: violation de contrainte d'intégrité (FKIDOPERATION_TARIF) - clé parent introuvable
avec deux tables, une table OPERATION qui est la table parent et la table TARIF qui est la table enfant dont une de ses colonnes est une FK de l'ID d'Operation

J'ai déjà regardé pas mal de poste sur internet sans succès.

Voici ce que je fais dans mon programme :

Code:

Session session = HibernateUtil.sessionFactory.openSession();
Transaction transaction = session.beginTransaction();

Operation newOperation = new Operation();
newOperation.setIdOperation((long)-1)); // let hibernate do the incrementation
session.save(newOperation);

Tarif newTarif = new Tarif();
newTarif.setIdTarif((long)-1);// let hibernate do the incrementation
newTarif.setOperation(newOperation);

newOperation.getTarifs().add(newTarif);
session.save(newTarif);
transaction.commit();

session.close();



Hibernate fait bien un INSERT en premier d'une Operation puis un INSERT d'un TARIF (c'est ici que j'obtiens l'erreur )

Voici le mapping des deux tables
Code:
<set name="tarifs" table="TARIF" inverse="true" >
            <key>
                <column name="FKIDOPERA" precision="11" scale="0" not-null="true" />
            </key>
            <one-to-many class="com.hibernate.Tarif" />
</set>

Code:
<many-to-one name="operation" class="com.hibernate.Operation" >
            <column name="FKIDOPERA" precision="11" scale="0" not-null="true" />
</many-to-one>


J'ai suivi la procédure suivante : http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/example-parentchild.html
mais j'ai toujours une erreur de clé parente introuvable.
Si vous avez besoin d'autres infos
Si quelqu'un peut m'aider ! Merci


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

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.