Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Spring: Attempting to execute an operation on a closed EntityManager.

I'm hoping some Spring gurus can help me out, whenever I try to
execute a query I get the error: Attempting to execute an operation on
a closed EntityManager.

I'm using Spring 2.5 + Tomcat6.

The weird thing is find's work fine. I'm launching tomcat with the
spring-aspects.jar for weaving. I'm new to this whole spring web stuff
so I am probably missing something, but the only thing I could find
online was to make sure I have the @Transactional annotations used
everywhere in my DAO class, which I do.

If I run in the debugger it looks like the EM is open as well, so I'm
kind of stumped. I suspect some weaving shenanigans, but I'm too much
of a neophyte at this right now to debug much more.

Many thanks :)

Here's my config:

<context:component-scan base-package="com.redacted" />

	<tx:annotation-driven mode="aspectj"/>
    <bean id="transactionManager"

	<bean id="dataSource"
		<property name="driverClassName" value="oracle.jdbc.OracleDriver" />
		<property name="url"
value="jdbc:oracle:thin:@redacted:1521:redacted" />
		<property name="username" value="redacted" />
		<property name="password" value="redacted" />

	<bean id="jpaAdapter"
   <property name="databasePlatform"
   <property name="showSql" value="true" />

  <bean id="loadTimeWeaver"

  <bean id="entityManagerFactory"
       <property name="persistenceUnitName" value="ProofOConcept"/>
       <property name="dataSource" ref="dataSource"/>
       <property name="jpaVendorAdapter" ref="jpaAdapter"/>
       <property name="loadTimeWeaver" ref="loadTimeWeaver"/>


	<util:list id="annotatedClasses">

Here's my DAO class:

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.eclipse.persistence.jpa.JpaEntityManager;
import org.eclipse.persistence.jpa.JpaHelper;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

public class BasicDao {

	@PersistenceContext(unitName = "ProofOConcept")
	private EntityManager em;

	@Transactional(readOnly = true)
	public <T> T find(Class<T> entityClass, Object primaryKey) {
		T result = em.find(entityClass, primaryKey);
		return result;


	@Transactional(readOnly = true)
	public <T> List<T> selectAll(Class<T> clazz) {
		JpaEntityManager jpaEm = JpaHelper.getEntityManager(em);
		Query query = jpaEm.createQuery(null, clazz);
		return (List<T>) query.getResultList();



Back to the top