Hi,
After having class loader problems trying to use Spring 2.5.5 with Toplink Essentials in GlassFish V2, I decided to use Hibernate as the JPA provider. That solved the problem, but created a new one. It seems to execute my query, but then has some problem which causes a rollback. Then there's some other problem in Spring because of this rollback:
applicationContext.xmlCode:[ERROR] AbstractEntityManagerImpl - -Unable to mark for rollback on PersistenceException: <java.lang.IllegalStateException> java.lang.IncompatibleClassChangeError: Class org.springframework.orm.jpa.EntityManagerHolder does not implement the requested interface org.springframework.transaction.support.ResourceHolder at org.springframework.transaction.support.ResourceHolderSynchronization.afterCompletion(ResourceHolderSynchronization.java:100) at org.springframework.transaction.support.TransactionSynchronizationUtils.invokeAfterCompletion(TransactionSynchronizationUtils.java:133) at org.springframework.transaction.support.AbstractPlatformTransactionManager.invokeAfterCompletion(AbstractPlatformTransactionManager.java:904) at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerAfterCompletion(AbstractPlatformTransactionManager.java:879) at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:707) at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:632) at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:314) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at $Proxy44.getProperty(Unknown Source) at com.example.model.UserContext.getTest(UserContext.java:22) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at javax.el.BeanELResolver.getValue(BeanELResolver.java:261) at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:143) at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:64) at com.sun.el.parser.AstValue.getValue(AstValue.java:138) at ...... [ERROR] TransactionSynchronizationUtils - -TransactionSynchronization.afterCompletion threw exception <java.lang.IncompatibleClassChangeError: Class org.springframework.orm.jpa.EntityManagerHolder does not implement the requested interface org.springframework.transaction.support.ResourceHolder>
persistence.xmlCode:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jee="http://www.springframework.org/schema/jee" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd"> <!-- enables interpretation of the @PersistenceUnit/@PersistenceContext annotations providing convenient access to EntityManagerFactory/EntityManager --> <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/> <!-- uses the persistence unit defined in the META-INF/persistence.xml JPA configuration file --> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"/> <!-- enables interpretation of the @Transactional annotation for declerative transaction managment using the specified transactionManager --> <tx:annotation-driven transaction-manager="transactionManager"/> <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/> <!-- DAOs --> <bean id="SystemSettingsDAO" class="com.example.dao.SystemSettingsDAOImpl"/> <!-- JSF MBeans --> <bean id="UserContext" class="com.example.model.UserContext" destroy-method="destroy" scope="session"> <property name="settingsDAO" ref="SystemSettingsDAO"/> </bean> </beans>
My DAO class:Code:<?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> <persistence-unit name="TestPU" transaction-type="JTA"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>jdbc/test</jta-data-source> <class>com.example.dao.SystemSettingEntity</class> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/> <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.SunONETransactionManagerLookup"/> <property name="hibernate.show_sql" value="true"/> <property name="hibernate.format_sql" value="true"/> </properties> </persistence-unit> </persistence>
Code:package com.example.dao; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.persistence.Query; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; @Transactional public class SystemSettingsDAOImpl implements SystemSettingsDAO { private EntityManager entityManager; @PersistenceContext(name="TestPU") public void setEntityManager(EntityManager newEm) { this.entityManager = newEm; } public String getProperty(String propName) { Query findQuery; SystemSettingEntity result; try { if (entityManager != null) { findQuery = entityManager.createNamedQuery( "SystemSettingEntity.findByKey"); findQuery.setParameter("key", propName); result = (SystemSettingEntity) findQuery.getSingleResult(); return result.getValue(); } else { return "***entityManager == null ****"; } } catch (Exception ex) { return "Failed: " + ex.getMessage(); } } }


Reply With Quote
Thanks, I'll start with that in the morning. I have a Spring 2.0 book here too. I read it cover-to-cover but that was a few months ago. Only now am I putting it to use. 