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.  [ 2 posts ] 
Author Message
 Post subject: probleme de mapping d'une relation directionnelle
PostPosted: Thu Nov 30, 2006 12:54 pm 
Newbie

Joined: Thu Nov 30, 2006 12:21 pm
Posts: 14
Bonjour,
j'ai deux bean : AnomalieFamille et Site , ils ont une relation un vers plusieurs , voici la portion du fichier de mapping relatif cette relation :
AnomalieFamille.hbm.xml :
<many-to-one
name="site"
class="com.webtiss.sita.sgp.model.Site"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="site_id"
/>
et Site.hbm.xml :
<bag
name="listFamilleAnomalie"
lazy="true"
inverse="true"
cascade="delete"
>
<cache
usage="read-write"
/>

<key
column="id"
>
</key>

<one-to-many
class="com.webtiss.sita.sgp.model.AnomalieFamille"
/>

</bag>

et quand j'essaye de enregistrer une nouvelle AnomalieFamille dans la base de donnée (SQL Server 2005) j'ai l'exection suivante :


2006-11-30 17:50:32,296 [ERROR] com.webtiss.sita.sgp.business.impl.AnomalieFamilleCommuneBusiness:170 - erreur depth save
com.webtiss.sita.sgp.Exception.InexbeeDAOException: could not insert: [com.webtiss.sita.sgp.model.AnomalieFamille]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [com.webtiss.sita.sgp.model.AnomalieFamille]
at com.webtiss.sita.sgp.dao.hibernate.generique.AbstractDAOHibernate.save(AbstractDAOHibernate.java:71)
at com.webtiss.sita.sgp.dao.hibernate.AnomalieFamilleDAOHibernate.save(AnomalieFamilleDAOHibernate.java:25)
at com.webtiss.sita.sgp.business.impl.AnomalieFamilleCommuneBusiness.depthSave(AnomalieFamilleCommuneBusiness.java:166)
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:318)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:203)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:162)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:209)
at $Proxy5.depthSave(Unknown Source)
at com.webtiss.sita.test.dao.AnoFamCDAOTestCase.testSave(AnoFamCDAOTestCase.java:29)
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 junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:228)
at junit.framework.TestSuite.run(TestSuite.java:223)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.hibernate.exception.ConstraintViolationException: could not insert: [com.webtiss.sita.sgp.model.AnomalieFamille]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:40)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2093)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2573)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:47)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:290)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:180)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:108)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
at org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:625)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:362)
at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:622)
at com.webtiss.sita.sgp.dao.hibernate.generique.AbstractDAOHibernate.save(AbstractDAOHibernate.java:69)
... 29 more
Caused by: java.sql.SQLException: The INSERT statement conflicted with the FOREIGN KEY constraint "FKCD3A7335C1370752". The conflict occurred in database "sgp", table "dbo.site", column 'id'.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:365)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2781)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2224)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:628)
at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:525)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:487)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:421)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:101)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:73)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)
... 48 more
2006-11-30 17:50:32,312 [DEBUG] org.springframework.orm.hibernate3.HibernateTransactionManager:705 - Triggering beforeCommit synchronization
2006-11-30 17:50:32,312 [DEBUG] org.springframework.orm.hibernate3.HibernateTransactionManager:718 - Triggering beforeCompletion synchronization
2006-11-30 17:50:32,312 [DEBUG] org.springframework.orm.hibernate3.HibernateTransactionManager:538 - Initiating transaction commit
2006-11-30 17:50:32,312 [DEBUG] org.springframework.orm.hibernate3.HibernateTransactionManager:554 - Committing Hibernate transaction on Session [org.hibernate.impl.SessionImpl@18e4327]
2006-11-30 17:50:32,343 [ERROR] org.hibernate.AssertionFailure:22 - an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: null id in com.webtiss.sita.sgp.model.AnomalieFamille entry (don't flush the Session after an exception occurs)
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:55)
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:157)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:113)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:558)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:540)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:510)
at org.springframework.transaction.interceptor.TransactionAspectSupport.completeTransactionAfterThrowing(TransactionAspectSupport.java:347)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:111)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:209)
at $Proxy5.depthSave(Unknown Source)
at com.webtiss.sita.test.dao.AnoFamCDAOTestCase.testSave(AnoFamCDAOTestCase.java:29)
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 junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:228)
at junit.framework.TestSuite.run(TestSuite.java:223)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
2006-11-30 17:50:32,343 [DEBUG] org.springframework.orm.hibernate3.HibernateTransactionManager:679 - Initiating transaction rollback on commit exception
org.hibernate.AssertionFailure: null id in com.webtiss.sita.sgp.model.AnomalieFamille entry (don't flush the Session after an exception occurs)
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:55)
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:157)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:113)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:558)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:540)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:510)
at org.springframework.transaction.interceptor.TransactionAspectSupport.completeTransactionAfterThrowing(TransactionAspectSupport.java:347)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:111)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:209)
at $Proxy5.depthSave(Unknown Source)
at com.webtiss.sita.test.dao.AnoFamCDAOTestCase.testSave(AnoFamCDAOTestCase.java:29)
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 junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:228)
at junit.framework.TestSuite.run(TestSuite.java:223)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
2006-11-30 17:50:32,343 [DEBUG] org.springframework.orm.hibernate3.HibernateTransactionManager:573 - Rolling back Hibernate transaction on Session [org.hibernate.impl.SessionImpl@18e4327]
2006-11-30 17:50:32,343 [DEBUG] org.springframework.orm.hibernate3.HibernateTransactionManager:747 - Triggering afterCompletion synchronization
2006-11-30 17:50:32,343 [DEBUG] org.springframework.orm.hibernate3.HibernateTransactionManager:633 - Closing Hibernate Session [org.hibernate.impl.SessionImpl@18e4327] after transaction
2006-11-30 17:50:32,359 [DEBUG] org.springframework.orm.hibernate3.SessionFactoryUtils:779 - Closing Hibernate Session
2006-11-30 17:50:32,359 [ERROR] org.springframework.transaction.interceptor.TransactionInterceptor:350 - Application exception overridden by commit exception
com.webtiss.sita.sgp.Exception.InexbeeBusinessException: could not insert: [com.webtiss.sita.sgp.model.AnomalieFamille]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [com.webtiss.sita.sgp.model.AnomalieFamille]
at com.webtiss.sita.sgp.business.impl.AnomalieFamilleCommuneBusiness.depthSave(AnomalieFamilleCommuneBusiness.java:172)
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:318)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:203)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:162)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:209)
at $Proxy5.depthSave(Unknown Source)
at com.webtiss.sita.test.dao.AnoFamCDAOTestCase.testSave(AnoFamCDAOTestCase.java:29)
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 junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:228)
at junit.framework.TestSuite.run(TestSuite.java:223)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)





le code que j'execute est le suivant :




public void depthSave(AnomalieFamilleCommune ano_f_c) throws InexbeeBusinessException {
try {
LOG.debug("0");

//
AnomalieFamille anofam ;
Site site;
// ajoute de la nouvelle famille dans tous les sites.
List listSites = this.getSiteDAO().getList();
for(int i = 0 ; i < listSites.size() ; i++) {
LOG.debug("1");
//
site = (Site)listSites.get(i);
//
anofam = new AnomalieFamille();
anofam.setCodeAnomalieFamille(ano_f_c.getCodeanofamc());
anofam.setLibelle(ano_f_c.getLibelle());
// construction de la liaison bidirectionelle hibernate
anofam.setSite(site);
//site.getListFamilleAnomalie().add(anofam);
this.getAnomalieFamilleDAO().save(anofam);
//this.getSiteDAO().save(site);
}
} catch (InexbeeDAOException e) {
LOG.error("erreur depth save",e);
//e.printStackTrace();
throw new InexbeeBusinessException(e);
}

}


est ce que quelqu'un aurai une idée de ce qui se passe ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 15, 2006 7:56 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Ben j'ai l'impression que le site n'est pas présent. Tu as vérifié que le site que tu récupères existe bien ? Rajoute un if(site==null){throw new IllegalArgumentException();} derrière ton session.get() pour voir ça...

Le session.get(), s'il ne trouve pas l'instance correspondant à la clé primaire que tu indiques, ne déclenchera aucune erreur, mais renverra simplement null, donc tu devrais vérifier que ce n'est pas ça.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


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