Hi all,
I've got lot of confusions after googling for spring transactions with eclipselink, tomcat and mysql. Please consider the following questions and guide me on this topic.
1. Can i run spring transactions with eclipseLink, tomcat and mysql enviornment? if so how is the config? i have used the following config and i get lock exceptions always.
Persistence.xml:
Spring-beans.xmlCode:<persistence-unit name="xxxxService" transaction-type="RESOURCE_LOCAL"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <class>...</class> <class>...</class> <class>...</class> <properties> .... </properties> </persistence-unit>
Java class:Code:<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect" /> <bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> <property name="jpaDialect" ref="jpaDialect" /> </bean> <bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter"> <property name="showSql" value="true" /> <property name="generateDdl" value="true" /> <property name="databasePlatform" value="org.eclipse.persistence.platform.database.MySQLPlatform" /> </bean> <bean class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean" id="entityManagerFactory"> <property name="jpaVendorAdapter" ref="jpaVendorAdapter" /> <property name="jpaDialect" ref="jpaDialect" /> <property name="persistenceUnitName" value="xxxxService" /> </bean> <tx:annotation-driven transaction-manager="transactionManager" /> <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
Am i doing anything wrong here? I'm not sure whether spring transaction handling works correctly with tomcat since i'm not using JTA transactions.Code:@Transactional public void saveSumthg(Sumthg sumthg) throws Exception{ someDAO.saveSumthg(sumthg); } @Transactional(propagation = Propagation.SUPPORTS, readOnly = true) public List<Sumthg> findActiveSumthgs(String username) { List<Sumthg> sumthgs = someDAO.findActiveSumthgs(username); return sumthgs ; }
2. With EclipseLInk and mysql, Id generation strategy goes with Sequence table and in the table only one row is updated for all transactions. I suspect that this causes lock issues. Am i correct? If so, how can i avoid this?
ID generation config in a Domain class is like this:
In mysql schema, a new table named SEQUENCE is created and a value is stored in it. Each time when a row is inserted, the id is taken from here i think. Since the same value is read and updated, i suspect that this can cause locking issues.Code:@Id @Column(name = "some_id", unique = true, nullable = false) @GeneratedValue(strategy = GenerationType.AUTO) private Long id;
If i'm correct, how can i avoid this issue??
Looking forward for your answers.


Reply With Quote
