|
Replies:
11
-
Last Post:
Feb 6, 2008 2:06 AM
by: woel
|
|
|
|
|
|
|
Hibernate and Spring not working on Glassfish 2
Posted:
Oct 29, 2007 4:57 AM
|
|
|
Hello,
I'm trying to port my app from Tomcat 6 to Glassfish 2. I'm using Spring 2 and Hibernate 3.2 In persistence.xml I set the transaction-type to RESOURCE_LOCAL but Glassfish complains every time that this can't be used:
com.sun.enterprise.deployment.backend.IASDeploymentException: Deployment Error -- The persistence-context-ref-name [GenericService/em] in module [C:\glassfish\domains\domain1\applications\j2ee-modules\bla] resolves to a persistence unit called [bla] which is of type RESOURCE_LOCAL. Only persistence units with transaction type JTA can be used as a container managed entity manager. Please verify your application.
Here is the persistence.xml: http://holl.co.at/download/glassfish/persistence.txt
And Springs applicationContext.xml: http://holl.co.at/download/glassfish/applicationContext.txt
Why is it not possible to use RESOURCE_LOCAL?
cheers, Gerald
--------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net For additional commands, e-mail: users-help@glassfish.dev.java.net
|
|
|
|
|
|
|
Re: Hibernate and Spring not working on Glassfish 2
Posted:
Oct 29, 2007 5:12 AM
in response to: Gerald Holl
|
|
|
Gerald Holl wrote: > Hello, > > I'm trying to port my app from Tomcat 6 to Glassfish 2. > I'm using Spring 2 and Hibernate 3.2 > In persistence.xml I set the transaction-type to RESOURCE_LOCAL but > Glassfish complains every time that this can't be used: > > com.sun.enterprise.deployment.backend.IASDeploymentException: > Deployment Error -- The persistence-context-ref-name > [GenericService/em] in module > [C:\glassfish\domains\domain1\applications\j2ee-modules\bla] resolves > to a persistence unit called [bla] which is of type RESOURCE_LOCAL. > Only persistence units with transaction type JTA can be used as a > container managed entity manager. Please verify your application. > > Here is the persistence.xml: > http://holl.co.at/download/glassfish/persistence.txt > > And Springs applicationContext.xml: > http://holl.co.at/download/glassfish/applicationContext.txt > > > Why is it not possible to use RESOURCE_LOCAL? > The reason is stated in the exception. It as follows: *only persistence units with transaction type JTA can be used as a container managed entity manager.*
You may ask what is a container managed entity manager. An entity manager whose life cycle (i.e., create & close) is controlled by container is called a container managed life cycle. An injected entity manager is an example of such type.
Two possible solutions: 1. Change transaction type to JTA in persistence.xml. OR 2. Use Application Managed entity manager (i.e. use EntityManagerFactory API to create EntityManager).
I don't know which of the two options is more appropriate for you. I guess it's the former one.
Thanks, Sahoo > cheers, > Gerald > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net > For additional commands, e-mail: users-help@glassfish.dev.java.net >
--------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net For additional commands, e-mail: users-help@glassfish.dev.java.net
|
|
|
|
|
|
|
|
Re: Hibernate and Spring not working on Glassfish 2
Posted:
Nov 2, 2007 8:56 AM
in response to: Sahoo
|
|
|
Sahoo wrote: > > Gerald Holl wrote: >> Hello, >> >> I'm trying to port my app from Tomcat 6 to Glassfish 2. >> I'm using Spring 2 and Hibernate 3.2 >> In persistence.xml I set the transaction-type to RESOURCE_LOCAL but >> Glassfish complains every time that this can't be used: >> >> com.sun.enterprise.deployment.backend.IASDeploymentException: >> Deployment Error -- The persistence-context-ref-name >> [GenericService/em] in module >> [C:\glassfish\domains\domain1\applications\j2ee-modules\bla] resolves >> to a persistence unit called [bla] which is of type RESOURCE_LOCAL. >> Only persistence units with transaction type JTA can be used as a >> container managed entity manager. Please verify your application. >> >> Here is the persistence.xml: >> http://holl.co.at/download/glassfish/persistence.txt >> >> And Springs applicationContext.xml: >> http://holl.co.at/download/glassfish/applicationContext.txt >> >> >> Why is it not possible to use RESOURCE_LOCAL? >> > The reason is stated in the exception. It as follows: > *only persistence units with transaction type JTA can be used as a > container managed entity manager.* > > You may ask what is a container managed entity manager. An entity > manager whose life cycle (i.e., create & close) is controlled by > container is called a container managed life cycle. An injected entity > manager is an example of such type. > > Two possible solutions: > 1. Change transaction type to JTA in persistence.xml. OR > 2. Use Application Managed entity manager (i.e. use EntityManagerFactory > API to create EntityManager). > > I don't know which of the two options is more appropriate for you. I > guess it's the former one.
I switched to EJB completely and removed all the Spring and Hibernate stuff.
Gerald -- http://holl.co.at
--------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net For additional commands, e-mail: users-help@glassfish.dev.java.net
|
|
|
|
|
|
|
|
Re: Hibernate and Spring not working on Glassfish 2
Posted:
Jan 4, 2008 8:05 AM
in response to: Sahoo
|
|
|
With Glassfish V1, I could use Spring with a container managed entity manager : @PersistenceContext(unitName = "PetCatalogPu") private EntityManager em; To do this, I had to configure The Entity Manager factory and the transactionManager in the spring applicationContext.xml . <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> .. <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory"/> </bean> ... this no longer works in Glassfish v2 (I get the same error as Gerald Holl), apparently because spring does not use JTA for this. I noticed that spring provides a JTA manager for Weblogic and Websphere: <bean id="transactionManager" class="org.springframework.transaction.jta.WebLogicJtaTransactionManager"> <property name="transactionManagerName" value="javax.transaction.TransactionManager"/> </bean>
Has anyone used Spring 2.x , JPA and Glassfish 2 successfully? Is the solution to only use Application Managed entity manager?
|
|
|
|
|
|
|
|
Re: Hibernate and Spring not working on Glassfish 2
Posted:
Jan 7, 2008 12:52 PM
in response to: caroljmcdonald
|
|
|
my Spring 2.5 , JPA and Glassfish v2 app works now with the transaction manager configured as follows:
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" />
I had actually tried this before, but it did NOT work when I had the tranasactionManager properties set as follows: <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory"/> <property name="dataSource" ref="dataSource"/> </bean>
|
|
|
|
|
|
|
|
Re: Hibernate and Spring not working on Glassfish 2
Posted:
Jan 31, 2008 12:01 PM
in response to: caroljmcdonald
|
|
|
Hi,
could you please given an example of your persistence.xml and applicationContext.xml Are you using RESOURCE_LOCAL or JTA? Are you using JPA?
Thanks
|
|
|
|
|
|
|
|
Re: Hibernate and Spring not working on Glassfish 2
Posted:
Jan 31, 2008 12:53 PM
in response to: caroljmcdonald
|
|
|
Thanks for your answer. Unfortunately I am looking for a working solution using JTA, JPA and Hibernte. I am struggling since a few days. I don't get it.
|
|
|
|
|
|
|
|
Re: Hibernate and Spring not working on Glassfish 2
Posted:
Feb 1, 2008 7:03 AM
in response to: klausstake
|
|
|
We're using hibernate with Glassfish. You could either put required hibernate in your gf lib directory or, as we do, together with your application in an ear file. Then just add the following line within the persistence-unit element in your persistence xml file: <provider>org.hibernate.ejb.HibernatePersistence</provider> Remember to specifiy jta-data-source and add the datasource in gf.
|
|
|
|
|
|
|
|
Re: Hibernate and Spring not working on Glassfish 2
Posted:
Feb 5, 2008 11:40 PM
in response to: woel
|
|
|
Actually I've tried what woel suggested. Unfortunately we had some major issues with this. E.g. I have seen a lot of cases where the Hibernate JPA implementation tries to load the persistence.xml without luck. The reason is that the jars in the gf lib directory are loaded by another classloader than the web application (which acutually contains the persistence.xml). Thus hibernate is not able to find the persistence.xml if you put the hibernate jars in the gf lib dir. Another issue I have found is some weird behaviour if you are not careful using the right web.xml schema. Glassfish may behave completely different depending on the the schema version you are using. I made some tests using 2.4 and 2.5 and found out that the deployment process completes with totally different results/errors sometimes. E.g. you might not be able to put in RESOURCE_LOCAL if you are using 2.5. Maybe this helps some other people who are in favour of RESOURCE_LOCAL instead of JTA
|
|
|
|
|
|
|
|
Re: Hibernate and Spring not working on Glassfish 2
Posted:
Feb 5, 2008 11:55 PM
in response to: klausstake
|
|
|
glassfish@javadesktop.org wrote: > Actually I've tried what woel suggested. > Unfortunately we had some major issues with this. E.g. I have seen a lot of cases where the Hibernate JPA implementation tries to load the persistence.xml without luck. The reason is that the jars in the gf lib directory are loaded by another classloader than the web application (which acutually contains the persistence.xml). Thus hibernate is not able to find the persistence.xml if you put the hibernate jars in the gf lib dir. > It's not just GlassFish, many appservers use different classloaders to load system classes vis-a-vis application classes. What is important is the class loader delegation chain and thread's context class loader. In GlassFish, an application's class loader delegates to the class loader that loads stuff from lib directory. We also set the application's class loader as the current thread's context class loader. Hibernate should be using thread's context class loader to load persistence.xml. I will be surprised to know if they actually don't. Which version of Hibernate are you using where you see such problems? Have you reported in their forum? > Another issue I have found is some weird behaviour if you are not careful using the right web.xml schema. Glassfish may behave completely different depending on the the schema version you are using. I made some tests using 2.4 and 2.5 and found out that the deployment process completes with totally different results/errors sometimes. E.g. you might not be able to put in RESOURCE_LOCAL if you are using 2.5. Maybe this helps some other people who are in favour of RESOURCE_LOCAL instead of JTA > One of the common problems encountered by users is that for them injection does not happen because they use schema version in web.xml as 2.4. It goes away when they change it to 2.5. Schema version comes into play because of the Java EE spec requirement; it is *not* a GlassFish specific behavior. Every compliant application server has to consider schema version of the descriptors to determine whether to process annotations or not.
I think the current issue is different. It appears to be a set up issue or a Sailfin thing. It is now being discussed in sailfin forum.
Thanks, Sahoo > [Message sent by forum member 'klausstake' (klausstake)] > > http://forums.java.net/jive/thread.jspa?messageID=257601 > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net > For additional commands, e-mail: users-help@glassfish.dev.java.net > >
--------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net For additional commands, e-mail: users-help@glassfish.dev.java.net
|
|
|
|
|
|
|
|
Re: Hibernate and Spring not working on Glassfish 2
Posted:
Feb 6, 2008 2:06 AM
in response to: Sahoo
|
|
|
We've never had any problems with hibernate when we put the libs in the gf lib directory. However, when we moved over to package the hibernate libs with the application we've had some problems from time to time with gf when running it from eclipse. Gf then tells us that it can't find the persistence unit. This might be an eclipse deployment issue. We never have any problems when we deploy the packaged ear file.
|
|
|
|
|