Hi to all,
I am new using hibernate and I really need you help guys. I'm having some problems with the error that I'm getting in Hibernat, that is "Unique Constraint Violated". I know what the error means but I don't know how to solve it with Hibernate.
The cenario is simple:
I have two tables, with the relation 1 to many. In the second table my primary key is of the first table and the primary key of the second table.
for this I have a class that has the attribute for the first table and a Set that contains the attributes for the second table.
The problem here is that hibernate is inserting two times the same record in the database that's why it gives me the exception.
With debuging I'm really sure that I don't have duplicated values inside the set so it must be something that I'm doing wrong on the hbm.xml file.
Bellow you'll find the hbm.xml file:
Code:
<joined-subclass
name="com.retek.rpm.domain.promotion.bo.TslPromotionComponentMultiBuyDetailImpl"
table="TSL_RPM_PROMO_COMP_M_B" dynamic-update="true"
persister="com.retek.rpm.domain.core.dao.RetekNormalizedEntityPersister">
<meta attribute="lazy-load-collection">zoneGroupNodes</meta>
<key column="RPM_PROMO_COMP_DETAIL_ID"/>
<property name="multiBuyPromotionType" column="MULTI_BUY_PROMO_TYPE" type="com.retek.rpm.domain.core.dao.codeconverter.TslMultiBuyTypeStringCodeConverter" not-null="true"/>
<!-- coupon to be included -->
<set name="listDetails" table="TSL_RPM_PROMO_COMP_M_B_DTL"
persister="com.retek.rpm.domain.core.dao.RetekBasicCollectionPersister">
<key column="RPM_PROMO_COMP_DETAIL_ID"/>
<composite-element class="com.retek.rpm.domain.promotion.bo.TslMultiBuyListImpl">
<property name="listDisplayId" column="LIST_ID"/>
<property name="listTypes" column="LIST_TYPE" type="com.retek.rpm.domain.core.dao.codeconverter.TslMultiBuyListTypeCodeConverter"/>
<property name="buyListType" column="BUY_ITEM_TYPE" type="com.retek.rpm.domain.core.dao.codeconverter.TslMultiBuyPromotionBuyTypeCodeConverter"/>
<property name="value" column="BUY_ITEM_VALUE"/>
<property name="retailChangeValue" access="field"
type="com.retek.rpm.domain.promotion.dao.RetailChangeValueUserType">
<column name="CHANGE_TYPE" not-null="false"/>
<column name="CHANGE_AMOUNT" not-null="false"/>
<column name="CHANGE_CURRENCY" not-null="false"/>
<column name="CHANGE_PERCENT" not-null="false"/>
<column name="CHANGE_SELLING_UOM" not-null="false"/>
<column name="VOUCHER_NUMBER" not-null="false"/>
<column name="VOUCHER_DESCRIPTION" not-null="false"/>
</property>
<property name="lockVersion" column="LOCK_VERSION" not-null="false"/>
<property name="getQuantity" column="GET_QUANTITY" type="com.retek.rpm.domain.promotion.dao.QuantityUserType" not-null="false"/>
</composite-element>
</set>
</joined-subclass>
Bellow you'll find the exception:
07/10/28 10:59:44 Hibernate: insert into TSL_RPM_PROMO_COMP_M_B_DTL (RPM_PROMO_COMP_DETAIL_ID, LIST_ID, LIST_TYPE, BUY_I
TEM_TYPE, BUY_ITEM_VALUE, CHANGE_TYPE, CHANGE_AMOUNT, CHANGE_CURRENCY, CHANGE_PERCENT, CHANGE_SELLING_UOM, VOUCHER_NUMBE
R, VOUCHER_DESCRIPTION, LOCK_VERSION, GET_QUANTITY) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
10:59:44,732 ERROR (RMICallHandler-0) [JDBCExceptionReporter] ORA-00001: unique constraint (RMS12.PKEY) violated
10:59:44,732 ERROR (RMICallHandler-0) [JDBCExceptionReporter] ORA-00001: unique constraint (RMS12.PKEY) violated
10:59:44,732 ERROR (RMICallHandler-0) [JDBCExceptionReporter] ORA-00001: unique constraint (RMS12.PKEY) violated
10:59:44,732 ERROR (RMICallHandler-0) [JDBCExceptionReporter] ORA-00001: unique constraint (RMS12.PKEY) violated
10:59:44,732 ERROR (RMICallHandler-0) [SessionImpl] Could not synchronize database state with session
2007-10-28 10:59:44.732 ERROR J2EE EJB8006 [PromotionComponentAppService:public com.retek.rpm.app.promotion.vo.Promotion
ComponentVO com.retek.rpm.app.promotion.service.PromotionComponentAppServiceEjb.save(com.retek.platform.service.ClientCo
ntext,java.lang.String,com.retek.platform.bo.IdentifiableReference,com.retek.rpm.app.promotion.event.PromotionComponentM
odifyEvent,java.util.List,java.util.List,java.lang.Boolean) throws com.retek.platform.exception.RetekBusinessException]
exception occurred during method invocation: oracle.oc4j.rmi.OracleRemoteException: com.retek.platform.persistence.Persi
stenceException: ERROR while flushing a Hibernate Session in HibernateJ2EEServiceContext.onComplete()
exception id: 1193549384732; nested exception is:
com.retek.platform.persistence.PersistenceException: ERROR while flushing a Hibernate Session in HibernateJ2EESe
rviceContext.onComplete()
exception id: 1193549384732
The question is, What am I doing wrong????
Many Thanks
Rui Felix