I understand that this is a very long question, but I wanted to ask everything because I was stuck with these things for more than 2 weeks, and I am in a situation to solve this within this week. Please help me in this matter.
I am using EclipseLink jpa version 2, Spring 3, jdk6, MySQL5 and tomcat7.
I set up the following in each of my DAO classes.
@PersistenceContext private EntityManager em;
I have the following in my Spring xml:
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource"> <property name="url" value="jdbc:mysql://localhost:3306/xxxxx"/> <property name="username" value="xxxx"/> <property name="password" value="xxxx"/> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> </bean> <bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory"> <property name="dataSource" ref="dataSource"/> <property name="jpaVendorAdapter" ref="jpaVendorAdapter"/> <property name="jpaDialect" ref="jpaDialect"/> </bean> <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" /> </bean> <bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect"/>
From Persistence.xml:
<persistence-unit name="xxxxx" transaction-type="RESOURCE_LOCAL"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <-- class mappings --> </persistence-unit>
I have little confusion about what I did:
Is EntityManager
introduced by Spring? (I understand that @PersistenceContext
is J2EE, so we wonder if it is being introduced without the input of Spring).
As I mentioned, I have introduced EntityManager
in all DAO classes. Is this a good practice? or should I do this Singleton, having a separate class, for example PersistenceManager
, which has the attribute EntityManager
, and the getEntityManager()
method?
As you can see above, I configured Spring transactions. But when I do CRUD operations continuously 2-3 times, the application gets stuck and fails with an EclipseLink exception saying it is unable to get a lock, timeout, etc. I am doing something wrong here or the absence of any transaction configurations
In the above configurations, I can only use the @Transactional
annotation with the default values PROPAGATION_REQUIRED,ISOLATION_DEFAULT
. If I change them for any other value, such as @Transactional(PROPAGATION_REQUIRED,ISOLATION_SERIALIZABLE)
, etc., application exclusion is excluded, since custom isolation levels are not supported. Again, I do not see any configurations?
Thanks.
source share