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 :

[hibernate] Violation de contrainte unique


Sujet :

Hibernate Java

  1. #1
    Nouveau Candidat au Club
    Inscrit en
    Juin 2006
    Messages
    2
    Détails du profil
    Informations forums :
    Inscription : Juin 2006
    Messages : 2
    Points : 1
    Points
    1
    Par défaut [hibernate] Violation de contrainte unique
    Bonjour,

    Je suis nouveau sur ce forum et débute en hibernate. Je ne comprends pas pourquoi lors d'une requete de lecture (récupération d'une personne et de ses associations avec les immeubles dans lesquels elle est) j'ai une erreur à cause d'une violation de contrainte (et donc d'une tentative d'insertion dans la base) ; pouvez vous m'expliquer pourquoi lors d'un "select" j'ai cette exception dûe à un "insert" ?
    Mon mapping est - il erroné ? Y'a-t-il quelquechose à indiquer pour éviter cet insert ?

    Merci d'avance pour votre aide.

    (à savoir que les traces que j'ai mises indiquent que les immeubles sont bien récupérés, mais c'est après la récupération, lors du "commit" que l'exception apparait)

    Hibernate version: 3

    Mapping de ma personne pour l'association vers les building :

    <set name="listPersonBuilding" table="T_PRSBUILD_EA4">
    <key column="PBU_FK_ID_PER" not-null="true"/>
    <composite-element class="com.sgcib.pops.business.model.person.PersonBuilding">
    <property name="officeName" column="PBU_VA_OFFICENAME" type="java.lang.String" length="50" />
    <property name="floor" column="PBU_VA_FLOOR" type="java.lang.String" length="20" />
    <property name="picture" column="PBU_VA_OFFICEPICTURE" type="java.lang.String" length="50" />
    <property name="active" type="java.lang.Boolean" column="PBU_BL_ACTIVE" />
    <property name="phone" column="PBU_VA_PHONE" type="java.lang.String" length="20" />
    <property name="cell" column="PBU_VA_CELL" type="java.lang.String" length="20" />
    <property name="fax" column="PBU_VA_FAX" type="java.lang.String" length="20" />
    <property name="principal" type="java.lang.Boolean" column="PBU_BL_PRINCIPAL" />
    <many-to-one name="building" column="PBU_FK_ID_BUI" />
    </composite-element>
    </set>


    Code de ma requete de lecture :

    Criteria lCriteria;
    Object lResult;
    try
    {
    lCriteria = getSession(true).createCriteria(pObjectClass);
    if (pObjectClass.getName().equals("Person"))
    {
    lCriteria.setFetchMode("listPersonActivity", FetchMode.JOIN);
    lCriteria.setFetchMode("listBuildings", FetchMode.JOIN);
    }
    lCriteria.add(Restrictions.idEq(pPk));
    if (lCriteria.list().size() <= 0)
    {
    throw new FinderException("Item with identifier :" + pPk + " not found.");
    }
    lResult = lCriteria.list().get(0);
    } catch (Throwable lThrowable)
    {
    sLogger.error("Problem during query execution : " + lThrowable.getMessage());
    throw new TechnicalException(lThrowable);
    }
    return lResult;

    Full stack trace of any exception that occurs:

    13:04:01,582 - DEBUG - org.springframework.orm.hibernate3.SessionFactoryUtils - Closing Hibernate Session
    org.springframework.dao.DataIntegrityViolationException: Hibernate operation: Could not execute JDBC batch update; SQL [insert into T_PRSBUILD_EA4 (PBU_FK_ID_PER, PBU_VA_OFFICENAME, PBU_VA_FLOOR, PBU_VA_OFFICEPICTURE, PBU_BL_ACTIVE, PBU_VA_PHONE, PBU_VA_CELL, PBU_VA_FAX, PBU_BL_PRINCIPAL, PBU_FK_ID_BUI) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]; ORA-00001: unique constraint (EA4MANAG2.PK_T_PRSBUILD_EA4) violated
    ; nested exception is java.sql.BatchUpdateException: ORA-00001: unique constraint (EA4MANAG2.PK_T_PRSBUILD_EA4) violated

    java.sql.BatchUpdateException: ORA-00001: unique constraint (EA4MANAG2.PK_T_PRSBUILD_EA4) violated

    at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
    at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:4133)
    at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:294)
    at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174)
    at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:74)
    at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:69)
    at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:150)
    at org.hibernate.persister.collection.AbstractCollectionPersister.deleteRows(AbstractCollectionPersister.java:975)
    at org.hibernate.action.CollectionUpdateAction.execute(CollectionUpdateAction.java:46)
    at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
    at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
    at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
    at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
    at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:584)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:496)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:469)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.doCommitTransactionAfterReturning(TransactionAspectSupport.java:266)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
    at $Proxy1.findItemByPk(Unknown Source)
    at com.sgcib.pops.persistence.person.dao.IntTestPersonHibernateDAOImpl.testFindItemByPk(IntTestPersonHibernateDAOImpl.java:178)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at junit.framework.TestCase.runTest(TestCase.java:154)
    at junit.framework.TestCase.runBare(TestCase.java:127)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:118)
    at junit.framework.TestSuite.runTest(TestSuite.java:208)
    at junit.framework.TestSuite.run(TestSuite.java:203)
    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)

    Name and version of the database you are using: Oracle 10 g

  2. #2
    Nouveau Candidat au Club
    Inscrit en
    Juin 2006
    Messages
    2
    Détails du profil
    Informations forums :
    Inscription : Juin 2006
    Messages : 2
    Points : 1
    Points
    1
    Par défaut
    Quelques traces de plus (showsql = true) :
    on voit bien qu'apres le select, au moment du commit il cherche à faire un delete puis deux insert ... mais je ne vois pas pourquoi.

    Merci d'avance.

    14:36:42,022 - DEBUG - org.springframework.transaction.support.TransactionSynchronizationManager - Retrieved value [org.springframework.orm.hibernate3.SessionHolder@7c3885] for key [org.hibernate.impl.SessionFactoryImpl@162e295] bound to thread [main]
    Hibernate: select this_.PER_N_ID as PER1_0_, this_.PER_DT_REHIRE_DATE as PER2_12_0_, this_.PER_VA_EXTCOMPANY as PER3_12_0_, this_.PER_VA_EXTCPYCODE as PER4_12_0_, this_.PER_DT_CREATION as PER5_12_0_, this_.PER_DT_UPDATE as PER6_12_0_, this_.PER_VA_USUAL_FIRST as PER7_12_0_, this_.PER_VA_USUAL_LAST as PER8_12_0_, this_.PER_VA_WINDOWS_LOGIN as PER9_12_0_, this_.PER_BL_SECURID as PER10_12_0_, this_.PER_BL_BLACKBERRY_ID as PER11_12_0_, this_.PER_BL_POWER_ATTORNEY as PER12_12_0_, this_.PER_VA_EMAIL as PER13_12_0_, this_.PER_VA_FIRST_NAME as PER14_12_0_, this_.PER_VA_MIDDLE_NAME as PER15_12_0_, this_.PER_VA_LAST_NAME as PER16_12_0_, this_.PER_VA_MAIDEN_NAME as PER17_12_0_, this_.PER_VA_BIRTHDATE as PER18_12_0_, this_.PER_VA_IGG as PER19_12_0_, this_.PER_DT_HIRE_DATE as PER20_12_0_, this_.PER_DT_SGCIB_START as PER21_12_0_, this_.PER_DT_CON_TERM as PER22_12_0_, this_.PER_DT_LOA_START as PER23_12_0_, this_.PER_DT_LOA_END as PER24_12_0_, this_.PER_DT_WALK_OUT as PER25_12_0_, this_.PER_BL_ADMIN_MANDATE as PER26_12_0_, this_.PER_N_TASK_MAIL_NOTIF as PER27_12_0_, this_.PER_DT_TASK_NOTIF_UPDATE as PER28_12_0_, this_.PER_BL_REQ_ACC_NOTIF as PER29_12_0_, this_.PER_BL_REQ_REJ_NOTIF as PER30_12_0_, this_.PER_VA_PAGER_NBR as PER31_12_0_, this_.PER_N_FTE as PER32_12_0_, this_.PER_DT_CHANGE_MGR as PER33_12_0_, this_.PER_VA_CHANGE_MGR as PER34_12_0_, this_.PER_DT_CHANGE_POS as PER35_12_0_, this_.PER_VA_CHANGE_POSMGR as PER36_12_0_, this_.PER_DT_CHANGE_DEPT as PER37_12_0_, this_.PER_VA_CHANGE_DEPTMGR as PER38_12_0_, this_.PER_VA_RC_LOCAL_ID as PER39_12_0_, this_.PER_VA_RC_LOCAL_NAME as PER40_12_0_, this_.PER_VA_RESP_TYPE as PER41_12_0_, this_.PER_VA_GLOBAL_HR_ID as PER42_12_0_, this_.PER_VA_LOCAL_HR_ID as PER43_12_0_, this_.PER_VA_VOCALRECORD as PER44_12_0_, this_.PER_VA_PHOTO as PER45_12_0_, this_.PER_BL_PHOTO_VISIBLE as PER46_12_0_, this_.PER_VA_POS_DESC as PER47_12_0_, this_.PER_VA_POS_NAME as PER48_12_0_, this_.PER_VA_HOME_PHONE as PER49_12_0_, this_.PER_VA_HOME_MOBILE as PER50_12_0_, this_.PER_BL_BCPROLE as PER51_12_0_, this_.PER_FK_ID_DPT as PER52_12_0_, this_.PER_FK_ID_LOCAL_DPT as PER53_12_0_, this_.PER_FK_ID_BCO1 as PER54_12_0_, this_.PER_FK_ID_BCO2 as PER55_12_0_, this_.PER_FK_ID_BRO1 as PER56_12_0_, this_.PER_FK_ID_BRO2 as PER57_12_0_, this_.PER_FK_ID_SRC_UPDATE as PER58_12_0_, this_.PER_FK_ID_SRC_CREATE as PER59_12_0_, this_.PER_FK_ID_CIT as PER60_12_0_, this_.PER_FK_ID_SIT as PER61_12_0_, this_.PER_FK_ID_OPER_MGR as PER62_12_0_, this_.PER_FK_ID_RESPONSIBLE as PER63_12_0_, this_.PER_FK_ID_JOB as PER64_12_0_, this_.PER_FK_ID_PTI as PER65_12_0_, this_.PER_FK_ID_CLA as PER66_12_0_, this_.PER_FK_ID_DTJ as PER67_12_0_, this_.PER_FK_ID_HRS as PER68_12_0_, this_.PER_FK_ID_CPY as PER69_12_0_, this_.PER_FK_ID_COU as PER70_12_0_, listperson2_.PAC_FK_ID_PER as PAC1_2_, listperson2_.PAC_DT_START as PAC2_2_, listperson2_.PAC_FK_ID_SCO as PAC3_2_, listperson2_.PAC_FK_ID_ACT as PAC4_2_, listperson2_.PAC_FK_ID_PER_MGR as PAC5_2_ from T_PERSON_EA4 this_ left outer join T_PERSACTIV_EA4 listperson2_ on this_.PER_N_ID=listperson2_.PAC_FK_ID_PER where this_.PER_N_ID = ?
    Hibernate: select listperson0_.PBU_FK_ID_PER as PBU1_0_, listperson0_.PBU_VA_OFFICENAME as PBU2_0_, listperson0_.PBU_VA_FLOOR as PBU3_0_, listperson0_.PBU_VA_OFFICEPICTURE as PBU4_0_, listperson0_.PBU_BL_ACTIVE as PBU5_0_, listperson0_.PBU_VA_PHONE as PBU6_0_, listperson0_.PBU_VA_CELL as PBU7_0_, listperson0_.PBU_VA_FAX as PBU8_0_, listperson0_.PBU_BL_PRINCIPAL as PBU9_0_, listperson0_.PBU_FK_ID_BUI as PBU10_0_ from T_PRSBUILD_EA4 listperson0_ where listperson0_.PBU_FK_ID_PER=?
    14:36:42,225 - DEBUG - org.springframework.transaction.interceptor.TransactionInterceptor - Invoking commit for transaction on com.sgcib.pops.persistence.common.ICommonDAO.findItemByPk
    14:36:42,225 - DEBUG - org.springframework.orm.hibernate3.HibernateTransactionManager - Triggering beforeCommit synchronization
    14:36:42,225 - DEBUG - org.springframework.orm.hibernate3.HibernateTransactionManager - Triggering beforeCompletion synchronization
    14:36:42,225 - DEBUG - org.springframework.orm.hibernate3.HibernateTransactionManager - Initiating transaction commit
    14:36:42,225 - DEBUG - org.springframework.orm.hibernate3.HibernateTransactionManager - Committing Hibernate transaction on Session [org.hibernate.impl.SessionImpl@13576a2]
    Hibernate: delete from T_PRSBUILD_EA4 where PBU_FK_ID_PER=? and PBU_VA_OFFICENAME=? and PBU_VA_FLOOR=? and PBU_VA_OFFICEPICTURE=? and PBU_BL_ACTIVE=? and PBU_VA_PHONE=? and PBU_VA_CELL=? and PBU_VA_FAX=? and PBU_BL_PRINCIPAL=? and PBU_FK_ID_BUI=?
    Hibernate: insert into T_PRSBUILD_EA4 (PBU_FK_ID_PER, PBU_VA_OFFICENAME, PBU_VA_FLOOR, PBU_VA_OFFICEPICTURE, PBU_BL_ACTIVE, PBU_VA_PHONE, PBU_VA_CELL, PBU_VA_FAX, PBU_BL_PRINCIPAL, PBU_FK_ID_BUI) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    Hibernate: insert into T_PRSBUILD_EA4 (PBU_FK_ID_PER, PBU_VA_OFFICENAME, PBU_VA_FLOOR, PBU_VA_OFFICEPICTURE, PBU_BL_ACTIVE, PBU_VA_PHONE, PBU_VA_CELL, PBU_VA_FAX, PBU_BL_PRINCIPAL, PBU_FK_ID_BUI) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    14:36:42,288 - DEBUG - org.springframework.jdbc.support.SQLErrorCodesFactory - Looking up default SQLErrorCodes for DataSource [org.apache.commons.dbcp.BasicDataSource@36527f]
    14:36:42,288 - DEBUG - org.springframework.jdbc.support.SQLErrorCodesFactory - Database product name found in cache for DataSource [org.apache.commons.dbcp.BasicDataSource@36527f]: name is 'Oracle'
    14:36:42,288 - DEBUG - org.springframework.jdbc.support.SQLErrorCodesFactory - SQL error codes for 'Oracle' found
    14:36:42,288 - DEBUG - org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator - Translating SQLException with SQLState '23000' and errorCode '1' and message [ORA-00001: unique constraint (EA4MANAG2.PK_T_PRSBUILD_EA4) violated
    ]; SQL was [insert into T_PRSBUILD_EA4 (PBU_FK_ID_PER, PBU_VA_OFFICENAME, PBU_VA_FLOOR, PBU_VA_OFFICEPICTURE, PBU_BL_ACTIVE, PBU_VA_PHONE, PBU_VA_CELL, PBU_VA_FAX, PBU_BL_PRINCIPAL, PBU_FK_ID_BUI) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)] for task [Hibernate operation: Could not execute JDBC batch update]
    14:36:42,288 - DEBUG - org.springframework.orm.hibernate3.HibernateTransactionManager - Initiating transaction rollback on commit exception
    org.springframework.dao.DataIntegrityViolationException: Hibernate operation: Could not execute JDBC batch update; SQL [insert into T_PRSBUILD_EA4 (PBU_FK_ID_PER, PBU_VA_OFFICENAME, PBU_VA_FLOOR, PBU_VA_OFFICEPICTURE, PBU_BL_ACTIVE, PBU_VA_PHONE, PBU_VA_CELL, PBU_VA_FAX, PBU_BL_PRINCIPAL, PBU_FK_ID_BUI) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]; ORA-00001: unique constraint (EA4MANAG2.PK_T_PRSBUILD_EA4) violated
    ; nested exception is java.sql.BatchUpdateException: ORA-00001: unique constraint (EA4MANAG2.PK_T_PRSBUILD_EA4) violated

Discussions similaires

  1. ORA-00001: violation de contrainte unique
    Par other1234 dans le forum Forms
    Réponses: 5
    Dernier message: 08/05/2012, 20h16
  2. Réponses: 4
    Dernier message: 13/03/2012, 11h37
  3. Error ORA-00001: violation de contrainte unique
    Par delilou dans le forum Développement de jobs
    Réponses: 4
    Dernier message: 17/03/2011, 17h26
  4. violation de contrainte unique (KOLOK.IDCONFIG_PK)
    Par Sephiroth Lune dans le forum Administration
    Réponses: 12
    Dernier message: 20/04/2007, 11h51
  5. Réponses: 2
    Dernier message: 13/02/2006, 11h13

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