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 :

Detached Entity après un saveOrUpdate


Sujet :

Hibernate Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre émérite
    Avatar de Cafeinoman
    Homme Profil pro
    Couteau suisse d'une PME
    Inscrit en
    Octobre 2012
    Messages
    628
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Couteau suisse d'une PME

    Informations forums :
    Inscription : Octobre 2012
    Messages : 628
    Par défaut Detached Entity après un saveOrUpdate
    Bonjour,

    je suis confronté à un soucis dans mes tests que je ne comprend pas. Je test ma couche de DAO, et j'ai l'exception suivante de levée (en résumé) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    javax.ejb.EJBException: java.lang.IllegalArgumentException: Removing a detached instance org.javacrea.gestioncontacts.pu.Contact#1
                        at org.javacrea.test.gestioncontacts.TestDAO.createContact(TestDAO.java:91)
    Caused by: java.lang.IllegalArgumentException: Removing a detached instance org.javacrea.gestioncontacts.pu.Contact#1
    Le code du test est le suivant :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    @RunWith(Arquillian.class)
    public class TestDAO {
     
    	@Inject
    	private GestionContacts fichier;
     
    	@Deployment
    	public static Archive<?> createDeployment() {
    		return ShrinkWrap
    				.create(JavaArchive.class, "DAOTest.jar")
    				.addClasses(GestionContacts.class, GestionContactsLocal.class, GestionContactsRemote.class, GestionContactsImpl.class, NullCriteriaValueException.class, MissingCVLineDatesException.class)
    				.addPackage(Contact.class.getPackage())
    				.addAsManifestResource("META-INF/test-beans.xml", "beans.xml")
    				.addAsResource("META-INF/test-persist.xml","META-INF/persistence.xml");
    	}
     
     
    	public void injectFichier(){
    		Assert.assertNotNull(fichier);
    		Assert.assertEquals("OK", fichier.test());
    	}
     
     
    	public void vider(){
    		fichier.closeSession();
    		List<Contact> all = fichier.chargerFichier();
    		for(Contact c : all){
    			fichier.updateContact(c);
    			fichier.deleteContact(c);
    		}
    		fichier.saveSession();
    	}
     
     
    	public void createContact() throws ParseException, MissingCVLineDatesException{
    		Contact moi = fichier.createContact("Monsieur","Delalleau", "François");
    		Assert.assertNotNull(moi);
    		Assert.assertTrue(moi.getId()!=null);
    		int i = moi.getId();
    		moi.addAdressePerso(new Adresse("mon adresse", "92110", "Clichy", null));
    		moi.addEmail(new Email("f.delalleau@gmail.com"));
    		moi.addTelephone(new LigneDirecte("0686000000"));
    		boolean saved = fichier.updateContact(moi);
    		Assert.assertTrue(saved);
    		moi = fichier.trouverContact("Delalleau").get(0);
    		Assert.assertEquals("François", moi.getPrenom());
    		fichier.closeSession();
    		Assert.assertNotNull(fichier.readContact(i));
    		moi = fichier.readContact(i);
    		boolean	persistent = fichier.updateContact(moi);
    		Assert.assertTrue(persistent);
    		fichier.deleteContact(moi);                         // => l'erreur est ici
    		Assert.assertNull(fichier.readContact(i));
    		System.out.println("CRUD contact OK!");
    		fichier.closeSession();
    	}
     
    	@Test
    	public void runTest() throws ParseException, MissingCVLineDatesException{
    		injectFichier();
    		vider();
    		createContact();
    		vider();
    	}
    }
    Et la classe de DAO (je zappe les méthodes non employées dans ce test):

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    @Singleton
    @ApplicationScoped
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public class GestionContactsImpl implements GestionContactsLocal,
    		GestionContactsRemote {
     
    	private Integer dirtyCount = 0;
     
    	@PersistenceContext(unitName = "GestionContacts")
    	private Session session;
     
    	@PostConstruct
    	public void checkFlush() {
    		session.setFlushMode(FlushMode.COMMIT);
    	}
     
    	public String test() {
    		return "OK";
    	}
     
    	@SuppressWarnings("unchecked")
    	public List<Contact> chargerFichier() {
    		isTooDirty();
    		return session.createQuery("select c from Contact c").list();
    	}
     
    	@SuppressWarnings("unchecked")
    	public List<Contact> trouverContact(String nom) {
    		isTooDirty();
    		return session
    				.createQuery("select c from Contact c where c.nom like :nom")
    				.setParameter("nom", nom).list();
    	}
     
    	...
     
    	@Override
    	public Contact createContact(String titre, String nom, String prenom) {
    		Contact contact = new Contact();
    		contact.setTitre(titre);
    		contact.setNom(nom);
    		contact.setPrenom(prenom);
    		session.save(contact);
    		isTooDirty();
    		return contact;
    	}
     
    	@Override
    	public Contact readContact(Integer id) {
    		isTooDirty();
    		Contact c = (Contact) session.get(Contact.class, id);
    		if(c!=null){
    		return c;
    		} else {
    			throw new EntityNotFoundException();
    		}
    	}
     
    	@Override
    	public boolean updateContact(Contact contact) {
    		session.saveOrUpdate(contact);
    		isTooDirty();
    		return session.contains(contact);
    	}
     
    	@Override
    	public boolean deleteContact(Contact contact) {
    		session.delete(contact);
    		isTooDirty();
    		return !session.contains(contact);
    	}
     
    	@Override
    	public void saveSession() {
    		session.flush();
    	}
     
    	@Override
    	public void closeSession() {
    		session.flush();
    		session.clear();
    	}
     
    	private void isTooDirty() {
    		if(session.isDirty()){
    			dirtyCount++;
    		}
    		if(dirtyCount>10){
    			saveSession();
    		}
    	}
    J'ai probablement mal compris quelque chose dans l'utilisation de Hibernate, si quelqu'un peut m'éclairer.

  2. #2
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    tu peux nous expliquer comment tu gère tes sessions? Parce que je vois un closeSession, mais pas de réouverture par la suite. Tout ça m'a l'air "bizzare". Normalement après avoir fermé une session hibernate tu devrais en ouvrir une nouvelle. Ici tu ne le fais pas, donc je suppose que hibernate travaille hors session, ce qui pose problème pour le delete.

  3. #3
    Membre émérite
    Avatar de Cafeinoman
    Homme Profil pro
    Couteau suisse d'une PME
    Inscrit en
    Octobre 2012
    Messages
    628
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Couteau suisse d'une PME

    Informations forums :
    Inscription : Octobre 2012
    Messages : 628
    Par défaut
    La session est gérée en JTA par le serveur (EAP6). La méthode fichier.closeSession() est en fait :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    	@Override
    	public void closeSession() {
    		session.flush();
    		session.clear();
    	}
    Elle est appelé à la déconnexion d'un utilisateur, par pure paranoïa. J'aurai du appeler la méthode, je suis d'accord. Mais donc la session hibernate n'est pas fermé. Les opérations sont, dans l'ordre :

    création d'une instance avec new;
    session.save() de l'instance;
    récupération de l'id de l'instance;
    initialisation de colonnes optionnelle de l'instance;
    session.saveOrUpdate() de l'instance;
    remplacement de l'instance avec une query sur la colonne nom;
    session.flush();
    session.clear();
    récupération d'une instance avec session.get() sur l'id;
    session.saveOrUpdate() de l'instance;
    session.delete() de l'instance;
    session.flush();
    session.clear();

  4. #4
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    c'est une manière bizarre de faire. D'abord lancer des commit lors d'un flush n'est pas très propre. Ensuite les noms des méthodes sont ambigus. Mais soit. Tu peux nous donner la stacktrace complète?

  5. #5
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Billets dans le blog
    1
    Par défaut
    Il y a un truc que je ne comprends pas, avec un contexte JTA, c'est le conteneur qui gère la transaction, pas le programme.
    Tu ne serais pas en EXTENDED ?
    Peux-tu montrer le persistence.xml ?
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  6. #6
    Membre émérite
    Avatar de Cafeinoman
    Homme Profil pro
    Couteau suisse d'une PME
    Inscrit en
    Octobre 2012
    Messages
    628
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Couteau suisse d'une PME

    Informations forums :
    Inscription : Octobre 2012
    Messages : 628
    Par défaut
    La stacktrace

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    javax.ejb.EJBException: java.lang.IllegalArgumentException: Removing a detached instance org.javacrea.gestioncontacts.pu.Contact#1
    	at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:189)
    	at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:274)
    	at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:339)
    	at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:238)
    	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    	at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)
    	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    	at org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory$1.processInvocation(ShutDownInterceptorFactory.java:64)
    	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    	at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59)
    	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    	at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
    	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    	at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:55)
    	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    	at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45)
    	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    	at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
    	at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165)
    	at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:182)
    	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    	at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
    	at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:72)
    	at org.javacrea.gestioncontacts.dao.GestionContactsLocal$$$view3.deleteContact(Unknown Source)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:606)
    	at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:267)
    	at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:52)
    	at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:137)
    	at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:263)
    	at org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler.invoke(EnterpriseBeanProxyMethodHandler.java:115)
    	at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:56)
    	at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:105)
    	at org.javacrea.gestioncontacts.dao.impl.GestionContacts$GestionContactsLocal$944501327$Proxy$_$$_Weld$Proxy$.deleteContact(GestionContacts$GestionContactsLocal$944501327$Proxy$_$$_Weld$Proxy$.java)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:606)
    	at org.jboss.weld.bean.proxy.AbstractBeanInstance.invoke(AbstractBeanInstance.java:45)
    	at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:105)
    	at org.jboss.weld.proxies.GestionContacts$GestionContactsLocal$944501327$Proxy$_$$_WeldClientProxy.deleteContact(GestionContacts$GestionContactsLocal$944501327$Proxy$_$$_WeldClientProxy.java)
    	at org.javacrea.test.gestioncontacts.TestDAO.createContact(TestDAO.java:91)
    	at org.javacrea.test.gestioncontacts.TestDAO.runTest(TestDAO.java:101)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:606)
    	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    	at org.jboss.arquillian.junit.Arquillian$6$1.invoke(Arquillian.java:270)
    	at org.jboss.arquillian.container.test.impl.execution.LocalTestExecuter.execute(LocalTestExecuter.java:60)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:606)
    	at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
    	at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
    	at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
    	at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
    	at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
    	at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
    	at org.jboss.arquillian.container.test.impl.execution.ContainerTestExecuter.execute(ContainerTestExecuter.java:38)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:606)
    	at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
    	at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
    	at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
    	at org.jboss.arquillian.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:89)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:606)
    	at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
    	at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
    	at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:75)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:606)
    	at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
    	at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
    	at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:60)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:606)
    	at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
    	at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
    	at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
    	at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.test(EventTestRunnerAdaptor.java:111)
    	at org.jboss.arquillian.junit.Arquillian$6.evaluate(Arquillian.java:263)
    	at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:226)
    	at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)
    	at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
    	at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:240)
    	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    	at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:185)
    	at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)
    	at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
    	at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:199)
    	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    	at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:147)
    	at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
    	at org.junit.runner.JUnitCore.run(JUnitCore.java:138)
    	at org.jboss.arquillian.junit.container.JUnitTestRunner.execute(JUnitTestRunner.java:65)
    	at org.jboss.arquillian.protocol.jmx.JMXTestRunner.runTestMethodInternal(JMXTestRunner.java:129)
    	at org.jboss.arquillian.protocol.jmx.JMXTestRunner.runTestMethod(JMXTestRunner.java:108)
    	at org.jboss.as.arquillian.service.ArquillianService$ExtendedJMXTestRunner.runTestMethod(ArquillianService.java:214)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:606)
    	at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:75)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:606)
    	at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:279)
    	at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:112)
    	at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:46)
    	at com.sun.jmx.mbeanserver.MBeanIntrospector.invokeM(MBeanIntrospector.java:237)
    	at com.sun.jmx.mbeanserver.PerInterface.invoke(PerInterface.java:138)
    	at com.sun.jmx.mbeanserver.MBeanSupport.invoke(MBeanSupport.java:252)
    	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
    	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
    	at org.jboss.as.jmx.PluggableMBeanServerImpl$TcclMBeanServer.invoke(PluggableMBeanServerImpl.java:1469)
    	at org.jboss.as.jmx.PluggableMBeanServerImpl.invoke(PluggableMBeanServerImpl.java:730)
    	at org.jboss.remotingjmx.protocol.v2.ServerProxy$InvokeHandler.handle(ServerProxy.java:952)
    	at org.jboss.remotingjmx.protocol.v2.ServerCommon$MessageReciever$1$1.run(ServerCommon.java:153)
    	at org.jboss.as.jmx.ServerInterceptorFactory$Interceptor$1.run(ServerInterceptorFactory.java:75)
    	at org.jboss.as.jmx.ServerInterceptorFactory$Interceptor$1.run(ServerInterceptorFactory.java:70)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at javax.security.auth.Subject.doAs(Subject.java:415)
    	at org.jboss.as.controller.AccessAuditContext.doAs(AccessAuditContext.java:94)
    	at org.jboss.as.jmx.ServerInterceptorFactory$Interceptor.handleEvent(ServerInterceptorFactory.java:70)
    	at org.jboss.remotingjmx.protocol.v2.ServerCommon$MessageReciever$1.run(ServerCommon.java:149)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    	at java.lang.Thread.run(Thread.java:744)
    Caused by: java.lang.IllegalArgumentException: Removing a detached instance org.javacrea.gestioncontacts.pu.Contact#1
    	at org.hibernate.ejb.event.EJB3DeleteEventListener.performDetachedEntityDeletionCheck(EJB3DeleteEventListener.java:67)
    	at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:107)
    	at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:74)
    	at org.hibernate.internal.SessionImpl.fireDelete(SessionImpl.java:963)
    	at org.hibernate.internal.SessionImpl.delete(SessionImpl.java:936)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:606)
    	at org.jboss.as.jpa.container.EntityManagerUnwrappedTargetInvocationHandler.invoke(EntityManagerUnwrappedTargetInvocationHandler.java:61)
    	at com.sun.proxy.$Proxy58.delete(Unknown Source)
    	at org.javacrea.gestioncontacts.dao.impl.GestionContactsImpl.deleteContact(GestionContactsImpl.java:160)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:606)
    	at org.jboss.as.ee.component.ManagedReferenceMethodInterceptorFactory$ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptorFactory.java:72)
    	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    	at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
    	at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:58)
    	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    	at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:374)
    	at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:129)
    	at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:137)
    	at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:58)
    	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    	at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
    	at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:58)
    	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    	at org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43)
    	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    	at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:374)
    	at org.jboss.as.ejb3.concurrency.ContainerManagedConcurrencyInterceptor.processInvocation(ContainerManagedConcurrencyInterceptor.java:104)
    	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    	at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:74)
    	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    	at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)
    	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    	at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
    	at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53)
    	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    	at org.jboss.as.ejb3.component.singleton.SingletonComponentInstanceAssociationInterceptor.processInvocation(SingletonComponentInstanceAssociationInterceptor.java:52)
    	at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288)
    	at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:272)
    	... 149 more
    et le persistence :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence xmlns="http://java.sun.com/xml/ns/persistence"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
    	version="2.0">
    	<persistence-unit name="GestionContacts"
    		transaction-type='JTA'>
    		<jta-data-source>java:jboss/datasources/gestioncontactsV2</jta-data-source>
    		<class>org.javacrea.gestioncontacts.pu.Adresse</class>
    		<class>org.javacrea.gestioncontacts.pu.AdressePerso</class>
    		<class>org.javacrea.gestioncontacts.pu.AdressePro</class>
    		<class>org.javacrea.gestioncontacts.pu.Collectivite</class>
    		<class>org.javacrea.gestioncontacts.pu.Commune</class>
    		<class>org.javacrea.gestioncontacts.pu.Contact</class>
    		<class>org.javacrea.gestioncontacts.pu.CV</class>
    		<class>org.javacrea.gestioncontacts.pu.Departement</class>
    		<class>org.javacrea.gestioncontacts.pu.Elu</class>
    		<class>org.javacrea.gestioncontacts.pu.Email</class>
    		<class>org.javacrea.gestioncontacts.pu.Entreprise</class>
    		<class>org.javacrea.gestioncontacts.pu.EtablissementSuperieur</class>
    		<class>org.javacrea.gestioncontacts.pu.Etudiant</class>
    		<class>org.javacrea.gestioncontacts.pu.LigneCV</class>
    		<class>org.javacrea.gestioncontacts.pu.LigneDirecte</class>
    		<class>org.javacrea.gestioncontacts.pu.Orga</class>
    		<class>org.javacrea.gestioncontacts.pu.Region</class>
    		<class>org.javacrea.gestioncontacts.pu.Salarie</class>
    		<class>org.javacrea.gestioncontacts.pu.Statut</class>
    		<class>org.javacrea.gestioncontacts.pu.Telephone</class>
    		<properties>
    			<property name="hibernate.show_sql" value="true" />
    		</properties>
    	</persistence-unit>
    </persistence>
    Par contre j'ai du mal comprendre un truc. Pour moi, je ne fait que des flush et des clear de la session hibernate, donc je force les requêtes vers la base et je vide le cache hibernate. Je ne touche pas à la transaction en elle-même, pas de commit, rien. Et le flushMode est sur commit, c'est pour ça que je fais des flush quand je juge que la session a trop de données non sauvegardées. Après si vous me dite qu'il vaut mieux ne pas toucher à tout ça et laisser le flushmode auto sans jamais faire de flush ou clear manuel, je veux bien vous croire...

Discussions similaires

  1. Réponses: 9
    Dernier message: 09/05/2011, 21h25
  2. detached entity passed to persist
    Par snipes dans le forum JPA
    Réponses: 2
    Dernier message: 06/08/2009, 15h19
  3. (debian,eclipse 3.4)detached entity pased to persist
    Par olivier57b dans le forum JPA
    Réponses: 9
    Dernier message: 07/03/2009, 12h27
  4. [EJB3 Entity] detached entity passed to persist
    Par maysam dans le forum Java EE
    Réponses: 3
    Dernier message: 03/12/2008, 13h43
  5. Réponses: 4
    Dernier message: 07/03/2007, 12h08

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