When persisting a parent, child relationship - cascaded from parent to child - with the child having a composite unique key configured as:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-
"http:>
<hibernate-mapping package="com.qumu">
<class name="MetadataValue" table="metadata_value">
<id column="id" name="id" type="long">
<generator class="native">
<param name="sequence">hibernate_sequence</param>
</generator>
</id>
<properties name="unique-props" unique="true">
<property column="guid" name="guid" not-null="true" type="string"/>
<many-to-one class="com.qumu.Customer" column="customer_id" name="customer" not-null="true"/>
</properties>
</class>
</hibernate-mapping>
A BasicProxyFactoryImpl is used by Hibernate to proxy the composite unique key values. However, this factory generates proxies which share a ProxyConfiguration.Interceptor. As the interceptor holds the bean state during persistence, this leads to persistence failure under concurrent use. In our particular use case, this manifested as unique constraint failures as the guid property above was reused by threads sharing the interceptor. Proposed solution is to instantiate a new interceptor per innovation of BasicProxyFactoryImpl. getProxy() |