IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Hibernate Java Discussion :

Exception in thread "main" javax.persistence.EntityExistsException:


Sujet :

Hibernate Java

  1. #1
    Membre régulier
    Inscrit en
    Mai 2003
    Messages
    350
    Détails du profil
    Informations forums :
    Inscription : Mai 2003
    Messages : 350
    Points : 84
    Points
    84
    Par défaut Exception in thread "main" javax.persistence.EntityExistsException:
    J'ai un petit souci avec une insertion.
    Voici deux classes
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    public class Personne implements Serializable {
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    public class Occupation implements Serializable{
       @OneToOne(cascade = CascadeType.ALL)
        @JoinColumn(name="MATRICULE")
        private Personne personne;
    }
    Dans la classe Occupation je référence Personne

    Quand je veux insérer une occurrence d'opération en faisant ceci
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    Personne p1 = new Personne(, , , , ,);
    Occupation o1 = new Occupation("01/01/2009","30/06/2009");
    l'enregistrement se fait correctement en mettant automatiquement null ds la référence à Personne
    Mais quand je fais:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    Personne p1 = new Personne(, , , , ,);
    Occupation o1 = new Occupation("01/01/2009","30/06/2009");
    o1.setPersonne(p1);
    Ds ce cas j'ai l'erreur suivante:
    log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
    log4j:WARN Please initialize the log4j system properly.
    [TopLink Info]: 2009.02.04 08:36:34.375--ServerSession(29751107)--TopLink, version: Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))
    [TopLink Info]: 2009.02.04 08:36:34.718--ServerSession(29751107)--file:/C:/Netbeans/workspace/NetBeansProjects/HibernateTest/src/-jpa login successful
    Exception in thread "main" javax.persistence.EntityExistsException:
    Exception Description: Cannot persist detached object [P[1,9,Administarteur du trésor,Administarteur]].
    Class> mis.cinq.entites.Fonction Primary Key> [9]
    at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.persist(EntityManagerImpl.java:193)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:198)
    at $Proxy15.persist(Unknown Source)
    at mis.cinq.dao.Dao.saveOccupation(Dao.java:180)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at $Proxy18.saveOccupation(Unknown Source)
    at mis.cinq.service.Service.saveOccupations(Service.java:257)
    at mis.cinq.view.CreateDB.fill(CreateDB.java:97)
    at mis.cinq.view.CreateDB.main(CreateDB.java:37)
    Caused by: Exception [TOPLINK-7231] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.ValidationException
    Exception Description: Cannot persist detached object [P[1,9,Administarteur du trésor,Administarteur]].
    Class> mis.cinq.entites.Fonction Primary Key> [9]
    at oracle.toplink.essentials.exceptions.ValidationException.cannotPersistExistingObject(ValidationException.java:2156)
    at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.registerNotRegisteredNewObjectForPersist(UnitOfWorkImpl.java:3237)
    at oracle.toplink.essentials.internal.ejb.cmp3.base.RepeatableWriteUnitOfWork.registerNotRegisteredNewObjectForPersist(RepeatableWriteUnitOfWork.java:323)
    at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:3206)
    at oracle.toplink.essentials.mappings.ObjectReferenceMapping.cascadeRegisterNewIfRequired(ObjectReferenceMapping.java:655)
    at oracle.toplink.essentials.internal.descriptors.ObjectBuilder.cascadeRegisterNewForCreate(ObjectBuilder.java:1256)
    at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:3212)
    at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.persist(EntityManagerImpl.java:190)
    ... 21 more
    Java Result: 1
    BUILD SUCCESSFUL (total time: 5 seconds)

  2. #2
    Membre régulier Avatar de kaizokuni
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    83
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Juillet 2008
    Messages : 83
    Points : 95
    Points
    95
    Par défaut
    Salut

    t'essaye peut être d'insérer un objet Personne qui existe déjà dans la base

    http://java.sun.com/javaee/5/docs/ap...Exception.html

Discussions similaires

  1. [JavaMail] Exception in thread "main" javax.mail.AuthenticationFailedException
    Par mas12 dans le forum Concurrence et multi-thread
    Réponses: 1
    Dernier message: 14/05/2009, 11h57

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo