Thanks for your responses.
Your points are valid. Using serializable would be theoretically the better option. But using:
Code:
@Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.SERIALIZABLE)
// Not using synchronized just enhances the number of raceconditions, even with isolation = serializable
public synchronized Path2Uuid findOrCreate(String path) {
Path2Uuid path2Uuid = _path2UuidDao.findByPath(path);
if (path2Uuid != null) {
return path2Uuid;
}
path2Uuid = new Path2Uuid(path, _uuidGenerator.getUuid(path));
_path2UuidDao.makePersistent(path2Uuid);
return path2Uuid;
}
for the configuration:
Code:
<bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource">
<property name="alias" value="pool1"/>
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="driverUrl" value="jdbc:mysql://localhost/test"/>
<property name="user" value="root"/>
<property name="password" value=""/>
<property name="delegateProperties" value="user=root"/>
<property name="maximumConnectionCount" value="100"/>
<property name="minimumConnectionCount" value="10"/>
<property name="simultaneousBuildThrottle" value="100"/>
<property name="houseKeepingTestSql" value="select CURRENT_DATE"/>
</bean>
<bean id="hibernateProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<props>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="hibernate.connection.useUnicode">true</prop>
<prop key="hibernate.connection.characterEncoding">UTF8</prop>
</props>
</property>
</bean>
did not solve the problem (using mysql db). I still get race conditions, that 2 threads want to create the path. I'm not keen on diving possibly for days into database/pool/spring/hibernate configuration issues.
What dangers do you think lurk around when using the fix with the wrapped methods I'm using now (see my first posting)?
However I think your problem lies with the way proxies are being created, I think CGLIB of JdkDynamic proxies don't include the synchronized keyword.
Sure, it is an proxy issue. I found one reply by Rod Johnson, where he recommended using pool, if one has exactly such a problem. This doesn't appeal to me.
Thanks
- Hans