[
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:
applicationcontext.xml;
<context:component-scan base-package="com.redacted" />
<tx:annotation-driven mode="aspectj"/>
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory"/>
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<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>
<bean id="jpaAdapter"
class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
<property name="databasePlatform"
value="org.eclipse.persistence.platform.database.oracle.OraclePlatform"
/>
<property name="showSql" value="true" />
</bean>
<bean id="loadTimeWeaver"
class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="ProofOConcept"/>
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter" ref="jpaAdapter"/>
<property name="loadTimeWeaver" ref="loadTimeWeaver"/>
</bean>
<util:list id="annotatedClasses">
<value>com.redacted.*</value>
</util:list>
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;
@Transactional
@Repository
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();
}
}
./tch