Page 1 of 3 123 LastLast
Results 1 to 10 of 26

Thread: Class org.springframework.orm.jpa.EntityManagerHolder does not implement the requeste

  1. #1

    Default Class org.springframework.orm.jpa.EntityManagerHolder does not implement the requeste

    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:

    Code:
    [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>
    applicationContext.xml

    Code:
    <?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>
    persistence.xml

    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>
    My DAO class:

    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();
            }
        }
    }

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    I suspect again classloading issues. Check if the spring.jar or spring-[module].jar is only loaded once. So it should either reside only on your ears, server or web application classpath NOT on two or three, because that is going to cause these kind of issues.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3

    Default

    Quote Originally Posted by Marten Deinum View Post
    I suspect again classloading issues. Check if the spring.jar or spring-[module].jar is only loaded once. So it should either reside only on your ears, server or web application classpath NOT on two or three, because that is going to cause these kind of issues.
    I appreciate your response, but cannot see how that is possible:

    1) There are absolutely no other applications deployed on GlassFish V2 other than my own and the GlassFish web admin console.
    2) My program exists only in a .war file. There is only a single place that initializes spring: the web.xml points to Spring's servlet context listener.

    I wondered if I have correct compatible .jar files for Spring. All of them are version 2.5.5 except spring-dao which is 2.0.8, because that is the newest one in the various public Maven 2 repositories. I downloaded Spring 2.5.5 zip file from springframework.org and looked inside. There is no longer a spring-dao.jar file! Is it now deprecated?

    I removed spring-dao.jar from my Maven2 pom.xml and that exception is gone. Big surprise, another exception that ends with "AbstractEntityManagerImpl - -Unable to mark for rollback on PersistenceException: <java.lang.IllegalStateException>". The query shown below executes fine in the database if I replace the ? with real values.

    I'll keep puttering away at this a bit longer. I'm on day 4 now and I can't fathom how people are successfully using Spring in GlassFish unless they do not use TopLink Essentials as a JPA provider and do not use JTA.


    Thanks,
    Ryan


    Code:
    Hibernate: 
        select
            systemsett0_.key as key0_,
            systemsett0_.value as value0_ 
        from
            system_settings systemsett0_ 
        where
            systemsett0_.key=?
    [WARN] JDBCExceptionReporter - -SQL Error: 30000, SQLState: 42X01
    [ERROR] JDBCExceptionReporter - -Syntax error: Encountered "key" at line 1, column 21.
    java.lang.IllegalStateException
            at com.sun.jts.jta.TransactionManagerImpl.setRollbackOnly(TransactionManagerImpl.java:374)
            at com.sun.enterprise.distributedtx.J2EETransactionManagerImpl.setRollbackOnly(J2EETransactionManagerImpl.java:1185)
            at com.sun.enterprise.distributedtx.J2EETransactionManagerOpt.setRollbackOnly(J2EETransactionManagerOpt.java:500)
            at com.sun.enterprise.transaction.TransactionManagerHelper.setRollbackOnly(TransactionManagerHelper.java:88)
            at org.hibernate.ejb.AbstractEntityManagerImpl.markAsRollback(AbstractEntityManagerImpl.java:440)
            at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:595)
            at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:637)
            at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:107)
            at com.example.dao.SystemSettingsDAOImpl.getProperty(SystemSettingsDAOImpl.java:42)
            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 org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
            at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
            at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
            at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
            at $Proxy35.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 com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:206)
            at com.sun.facelets.el.ELText$ELTextVariable.writeText(ELText.java:184)
            at com.sun.facelets.el.ELText$ELTextComposite.writeText(ELText.java:108)
            at com.sun.facelets.compiler.TextInstruction.write(TextInstruction.java:45)
            at com.sun.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:39)
            at com.sun.facelets.compiler.UILeaf.encodeAll(UILeaf.java:149)
            at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
            at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
            at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
            at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
            at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
            at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
            at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:317)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
            at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
            at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:853)
            at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:703)
            at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:542)
            at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:474)
            at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:366)
            at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:767)
            at org.apache.jsp.forward_jsp._jspService(forward_jsp.java from :48)
            at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:93)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
            at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
            at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:470)
            at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:364)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
            at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:317)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:198)
            at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
            at .............
    [ERROR] AbstractEntityManagerImpl - -Unable to mark for rollback on PersistenceException:  <java.lang.IllegalStateException>

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    The jar spring-dao isn't there anymore because it's contents is now in spring-orm and spring-tx jar files. So if you have a spring-dao and one of the other jars this wil lead you into troubles also. So that at least explains your initial exception.

    I appreciate your response, but cannot see how that is possible:
    The fact that you are the only application doesn't mean that there is no other spring.jar or spring-[module].jar loaded. It still can be somewhere on the shared server or system classpath.

    Make sure that your properties for hibernate are ok and that your mapping is fine. Also instead of using setParameter try setString.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5

    Default

    Quote Originally Posted by Marten Deinum View Post
    The fact that you are the only application doesn't mean that there is no other spring.jar or spring-[module].jar loaded. It still can be somewhere on the shared server or system classpath.
    I think we are past the classloader problems now that spring-dao.jar is removed from my pom.xml, we know the GlassFish load time weaver was needed to share a classloader, and that it ends up using the EJBClassLoader (which fails). Switching to Hibernate JPA provider helped me past that issue.

    In any case, this is my development computer with GlassFish on it. I am in full control of this computer, and Spring has never been on it until Monday. I un-deployed the only app (mine) then searched the directory tree for spring. No matches.

    Quote Originally Posted by Marten Deinum View Post
    Make sure that your properties for hibernate are ok and that your mapping is fine. Also instead of using setParameter try setString.
    Since I use Hibernate as a JPA provider, I have an annotated entity and no mapping files. With Spring removed from the equation and using TopLink as JPA provider, I was able to query the DB using this entitiy so I know it is annotated properly.

    Yes I think my next challenge will be to figure out if Hibernate is mis-configured or Spring's entity manager. I noticed in my log file that something (Hibernate?) doesn't realize I'm using Postgres:

    Code:
    [INFO] SettingsFactory - -RDBMS: Apache Derby, version: 10.2.2.1 - (538595)
    [INFO] SettingsFactory - -JDBC driver: Apache Derby Embedded JDBC Driver, version: 10.2.2.1 - (538595)
    This is probably not your area of expertise but if you notice I missed something please let me know. I suspect it has something to do with some properties being defined in persistence.xml, and others being loaded from the JNDI DataSource.

    persistence.xml

    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="RESOURCE_LOCAL">
        <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.connection.driver_class" value="org.postgresql.Driver"/> 
            <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="false"/>
        </properties> 
      </persistence-unit>
    </persistence>
    applicationContext.xml

    Code:
    ...
    <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">
             <property name="jpaVendorAdapter">
                <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                    <property name="database" value="POSTGRESQL"/>
                </bean>
            </property>
        </bean>
    
        <tx:annotation-driven transaction-manager="transactionManager"/>
        <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
    ...

    Thanks,
    Ryan

  6. #6

    Default

    Quote Originally Posted by rdelaplante View Post
    Yes I think my next challenge will be to figure out if Hibernate is mis-configured or Spring's entity manager. I noticed in my log file that something (Hibernate?) doesn't realize I'm using Postgres:

    Code:
    [INFO] SettingsFactory - -RDBMS: Apache Derby, version: 10.2.2.1 - (538595)
    [INFO] SettingsFactory - -JDBC driver: Apache Derby Embedded JDBC Driver, version: 10.2.2.1 - (538595)
    This problem was fixed by telling persistence.xml to NOT use my JNDI data source, and to provide the details as properties instead:

    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.connection.driver_class" value="org.postgresql.Driver"/> 
            <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/test"/>
            <property name="hibernate.connection.username" value="postgres"/>
            <property name="hibernate.connection.password" value="postgres"/>
    
            <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="false"/>
        </properties> 
      </persistence-unit>
    </persistence>
    On day 4, I can finally query the database without errors! Now I need to verify that it works for all CRUD operations and that Spring container managed transactions really are working. I also need to learn a way to externalize database connection URL, username and password into a DataSource without breaking it. I should be able to handle that.

    Thanks again for your helpful suggestions. From this experience I would EJB 3 is easier. I write a class, deploy it, and it works. App servers come pre-configured out of the box with O/R mapper and transaction manager. I didn't have to spend 4 days to do that. When EJB 3.1 comes out and supports running in the servlet container, I will give it a look again. Having to deploy EJBs (3.0) in a separate .jar file in a .ear file is the biggest pain point for me. That's why I'm looking at Spring for this project.


    Thanks,
    Ryan

  7. #7
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    On day 4, I can finally query the database without errors! Now I need to verify that it works for all CRUD operations and that Spring container managed transactions really are working. I also need to learn a way to externalize database connection URL, username and password into a DataSource without breaking it. I should be able to handle that.
    That isn't the hardest thing it is quite easy actually.

    Strip down your persistence.xml

    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">
        <class>com.example.dao.SystemSettingEntity</class>
      </persistence-unit>
    </persistence>
    So really strip it down and put you configuration in the applicationContext.xml.

    Code:
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="org.postgresql.Driver" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
        <property name="url" value="${jdbc.url}" />
    </bean>
    
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="database" value="POSTGRESQL"/>
                <property name="showSql" value="true" />            
            </bean>
        </property>
    </bean>
    However you have a very other issue now. You use JTA transactions so you also need a container managed DataSource. Currently you use a local one (in the configuration I show and in the latest configuration you use).

    So although it appears to work it works outside of the jta transactions.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  8. #8

    Default

    Quote Originally Posted by Marten Deinum View Post
    That isn't the hardest thing it is quite easy actually.
    ...
    Strip down your persistence.xml
    ...
    So really strip it down and put you configuration in the applicationContext.xml.
    That just moves database configuration from one XML file inside my .war binary into another. I don't want to do a custom binary build for every server I deploy to. When I was using EJB 3.0, I was able to use a data source configured in the application server. Persistence.xml just referenced the JNDI name of the datasource.

    Having to switch to Hibernate seems to have been a GlassFish issue: TopLink needs a "load time weaver" to work with Spring, and GlassFish only offers an EJBClassLoader that doesn't work for my .war project. Having to move my data source configuration into persistence.xml seems to be a Hibernate problem. Even when persistence.xml only contained the JNDI datasource name, hibernate dialect and JTA info, it thought it was using Apache Derby and my queries would fail.

    I'll play some more with Hibernate Friday.

    However you have a very other issue now. You use JTA transactions so you also need a container managed DataSource. Currently you use a local one (in the configuration I show and in the latest configuration you use).

    So although it appears to work it works outside of the jta transactions.
    Thanks for the heads up. So, the battle isn't over yet.

  9. #9
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    That just moves database configuration from one XML file inside my .war binary into another. I don't want to do a custom binary build for every server I deploy to. When I was using EJB 3.0, I was able to use a data source configured in the application server. Persistence.xml just referenced the JNDI name of the datasource.
    May I suggest the reference guide and the sample applications they are quite clear.

    Code:
    <jee:jndi-lookup id="dataSource" jnd-name="jdbc/datasource" />
    Instead of the bean element and you use a application server configured one.

    You also might want to take a look at the new sample project for PetClinic that uses EclipseLink as a provider. Next to that I cannot imagine that there aren't people out there who aren't using GlassFish in combination with Hibernate.

    Come to think of it we actually use this combination in our BEJD training I believe. Let me see if I can peek in there.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  10. #10

    Default

    If I would have started with studying the PetClinic sample project I probably could have avoided all of this confusion 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.


    Thanks,
    Ryan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •