Re: Transaction Problems with OpenEJB-Hibernate on Tomcat
Hello Jean, Thanks for your valuable inputs. I'm able to resolve the error finally. I am very new to this OpenEJB & Hibernate. I had worked earlier on struts/jsf on websphere environment.. Basically, I had to deploy the web application having some business logic like user authetication done thru EJB which eventually use the hibernate to interact with database.. I wrote JUnits fr the same & tried to test my ejbs individually, there I found that entry for persitence unit was missing in persitence.xml. I correted & redeplyed the appilaction.. It ran smoothly. Im gld that this forum is there to help on openejb.. -Kedar -- View this message in context: http://openejb.979440.n4.nabble.com/Transaction-Problems-with-OpenEJB-Hibernate-on-Tomcat-tp1011003p3253414.html Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: Transaction Problems with OpenEJB-Hibernate on Tomcat
Hi Kedar, A JIRA already exists to add an Hibernate profile. So it will be easier to create an OpenEJB webapp using Hibernate instead of OpenJPA. I totally forgot to commit it, but I promise you to do it on next week (Monday or Tuesday) Jean-Louis -- View this message in context: http://openejb.979440.n4.nabble.com/Transaction-Problems-with-OpenEJB-Hibernate-on-Tomcat-tp1011003p3244787.html Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: Transaction Problems with OpenEJB-Hibernate on Tomcat
Hi all, I'm used to use Hibernate + OpenEJB. To avoid classloading issues for end users, I'm created an hibernate profile to create an OpenEJB webapp using Hibernate instead of OpenJPA. It's works fine with JPA on top of Hibernate. To be honest, never tried only with Hibernate. That's definitely possible. One point, the JTA transaction factory should not be set as you already discovered. The default value is ok. The transaction manager lookup is enough. By the way, if you use JPA and the persistence.xml file, you don't also need to set the transaction manager lookup because OpenEJB while set it for you when it discovers the persistence provider. Anyway, I don't know if that is possible for you, but it would be really easier to get a simple example. Is it something possible for you? If you can provide a small example (maven project to create the war file), i can definitely have a look and try to give you more hints. Jean-Louis -- View this message in context: http://openejb.979440.n4.nabble.com/Transaction-Problems-with-OpenEJB-Hibernate-on-Tomcat-tp1011003p3244776.html Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: Transaction Problems with OpenEJB-Hibernate on Tomcat
Hi Freeway, Thanks for the detail post on OpenEJB.. > I am also facing exact same issue while instantiating TransactionManagerLookup class. I would be very greateful, if you could provide me the changes u hv done in the Tomcat/lib, WEB-INF/lib folders to resolve the error. What was the root cause ? It looks like Tomat is looking for another Jar, & OpenEJB is requiring another. I Hope, you would be remembering the things, as this Post is one year older :) http://openejb.979440.n4.nabble.com/Transaction-Problems-with-OpenEJB-Hibernate-on-Tomcat-tp1011003p3243862.html Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: Transaction Problems with OpenEJB-Hibernate on Tomcat
For the record, I resolved this transaction commit-rollback problem using OpenEJB and Hibernate together, without the need for a custom JTA transaction factory class (although I wrote one that seemed to work). All the EJBs in this application are stateless session beans using container-managed transactions, so the off-the-shelf Hibernate class org.hibernate.transaction.CMTTransactionFactory worked fine. The data source connections are configured in openejb.xml, and the Tomcat webapp in which the EJBs are deployed has a WEB-INF/classes/META-INF/persistence.xml file like the following that references the Hibernate configuration file, where all other persistence-related settings are stored. 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";> org.hibernate.ejb.HibernatePersistence jdbc/MyDS jdbc/MyUnmanagedDS Also, some of my entries in the ejb-jar.xml file were wrong or missing, which was contributing to the problem. At any rate, if anyone else on this forum is having problems deploying OpenEJB with Hibernate on Tomcat, please reply and I will pass along any help that I can. Regards, Fred -- View this message in context: http://n4.nabble.com/Transaction-Problems-with-OpenEJB-Hibernate-on-Tomcat-tp1011003p1556932.html Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: Transaction Problems with OpenEJB-Hibernate on Tomcat
Fred, I would remove all the JTA/transaction factory stuff and assume a clean JPA bootstrap. For completeness, can you kindly send me your Hibernate configuration file? The stuff in that configuration file should move to the persistence.xml file instead. If you do end up needing to feed Hibernate a custom transaction factory, David and the other OpenEJB guys are probably the best people to help with that since they wrote the thing...but let's give this a spin first. Cheers, Reza = Author, EJB 3 in Action Expert Group Member, Java EE 6 and EJB 3.1 Resin EJB 3.1 Lite Container Lead freeway wrote: Hi Reza, Thanks for the quick response. I just tried placing the following persistence.xml file in the webapp's WEB-INF/classes/META-INF/ directory, but received the same runtime error from JTATransactionFactory. 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";> org.hibernate.ejb.HibernatePersistence jdbc/LsBpmDS This file references the same hibernate.cfg.xml file included in my previous post to obtain all Hibernate properties. I can see from the OpenEJB and Hibernate log files that this configuration was found and loaded at Tomcat startup. However, it still executes the class org.hibernate.transaction.JTATransactionFactory and fails to retrieve the UserTransaction object in the same way. Do I need to use a different OpenEJB-provided transaction factory class, or override the Hibernate-provided one myself? Or is my above configuration simply incorrect for using JPA in OpenEJB? Thx in advance, Fred Reza Rahman-2 wrote: Hi, I might have lost some context here, but have you tried simply defining your OpenEJB JTA data source persistence.xml instead of using hibernate.cfg? I am thinking this issue might be best resolved simply by going through the OpenEJB/JPA compatibility layer of Hibernate. Are you planning on using the JPA APIs or native Hibernate with OpenEJB? Note, the Hibernate team itself recommends JPA, you can configure Hibernate via persistence.xml and you can always get access to the native Hibernate session via EntityManager.getDelegate() if you really need it: http://bill.burkecentral.com/2007/07/06/co-existence-with-hibernate-jpa-and-ejb3/. It's certainly a lot simpler to use JPA with EJB 3.x instead of trying to inject native Hibernate objects directly. Hope it helps, Reza = Author, EJB 3 in Action Expert Group Member, Java EE 6 and EJB 3.1 Resin EJB 3.1 Lite Container Lead freeway wrote: I have made some progress sorting out general configuration errors from my Tomcat 6 environment, and can restate the transaction problem in more specific terms that will hopefully lead more directly to a solution. The specific errors mentioned in my first post were mainly the result of Tomcat classloader problems, resulting from various dependent classes deployed wrongly in the webapp WEB-INF/lib/ directory, Tomcat lib/ directory, or both. Many of the errors raised as a result of these problems are generic and misleading messages such as 'cannot instantiate class...', 'document error...', etc. (Classloader problems seem to be the root of all evil with things Tomcat.) However, after fixing these problems I am still unable to retrieve the JTA transaction properly from Hibernate 3. I have configured the environment to move the transaction-managed JDBC data source configuration from Tomcat's server.xml into openejb.xml, as follows. JdbcDriver com.mysql.jdbc.Driver JdbcUrl jdbc:mysql://localhost:3306/qadworkflow?autoReconnect=true UserName ... Password ... JtaManaged true InitialSize 0 MaxActive 20 MaxIdle 20 MinIdle 0 MaxWait -1 My hibernate.cfg.xml configuration is as follows (irrelevant settings omitted). java:comp/env/jdbc/LsBpmDS UserTransaction org.hibernate.transaction.JTATransactionFactory org.apache.openejb.hibernate.TransactionManagerLookup With the above I receive a stack overflow error at runtime when attempting to retrieve the JTA transaction. java.lang.StackOverflowError at java.lang.Character.digit(Unknown Source) at java.lang.Character.digit(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at java.text.MessageFormat.makeFormat(Unknown Source) at java.text.MessageFormat.applyPattern(Unknown Source) at java.text.MessageFormat.(Unknown Source) at java.text.MessageFormat.format(Unknown Source) at org.apache.naming.StringManager.getString(StringManager.java:121) at org.apache.naming.StringManager.getString(StringManager.java:144) at org.apache
Re: Transaction Problems with OpenEJB-Hibernate on Tomcat
e reviewed Hibernate, OpenEJB, and Tomcat debug logs and can at >> least >> verify that the Hibernate settings that I have tried are being used at >> runtime. However, these logs have not been of much help diagnosing the >> problem. >> >> >> Please suggest config changes that I made need, or point me to any custom >> class implementations that might help. >> >> >> >> >> Reza Rahman-2 wrote: >> >>> Let me see if I can help here, it'll take me a couple of days, >>> though...I'm swamped at the moment. I would think David could help >>> too... >>> >>> Cheers, >>> Reza >>> = >>> Author, EJB 3 in Action >>> Expert Group Member, Java EE 6 and EJB 3.1 >>> Resin EJB 3.1 Lite Container Lead >>> >>> >>> Jacek Laskowski wrote: >>> >>>> On Mon, Jan 11, 2010 at 4:32 AM, freeway wrote: >>>> >>>> >>>> >>>>> To close this message: I have seen many (rather confusing) posts and >>>>> partial >>>>> examples regarding the use of the config files persistence.xml, >>>>> services-jar.xml, and/or openejb-jar.xml files to define data source >>>>> resources, Hibernate properties, and transaction managers more >>>>> explicitly >>>>> inside OpenEJB. However, it seems to me based on other doc I have >>>>> read >>>>> that >>>>> using openejb.xml, ejb-jar.xml, and the native Hibernate files should >>>>> be >>>>> enough for a seemingly straightforward case like this one. If this is >>>>> wrong, please steer me in the right direction. >>>>> >>>>> >>>> I'm so glad you're building the stack with OpenEJB, but alas I won't >>>> be able to help you out with the problem at hand. I hope there're >>>> people in the mailing list who will share their findings with similar >>>> configurations and will provide a viable solution. >>>> >>>> Jacek >>>> >>>> >>>> >>> >>> >> >> > > > -- View this message in context: http://n4.nabble.com/Transaction-Problems-with-OpenEJB-Hibernate-on-Tomcat-tp1011003p1017159.html Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: Transaction Problems with OpenEJB-Hibernate on Tomcat
Hi, I might have lost some context here, but have you tried simply defining your OpenEJB JTA data source persistence.xml instead of using hibernate.cfg? I am thinking this issue might be best resolved simply by going through the OpenEJB/JPA compatibility layer of Hibernate. Are you planning on using the JPA APIs or native Hibernate with OpenEJB? Note, the Hibernate team itself recommends JPA, you can configure Hibernate via persistence.xml and you can always get access to the native Hibernate session via EntityManager.getDelegate() if you really need it: http://bill.burkecentral.com/2007/07/06/co-existence-with-hibernate-jpa-and-ejb3/. It's certainly a lot simpler to use JPA with EJB 3.x instead of trying to inject native Hibernate objects directly. Hope it helps, Reza = Author, EJB 3 in Action Expert Group Member, Java EE 6 and EJB 3.1 Resin EJB 3.1 Lite Container Lead freeway wrote: I have made some progress sorting out general configuration errors from my Tomcat 6 environment, and can restate the transaction problem in more specific terms that will hopefully lead more directly to a solution. The specific errors mentioned in my first post were mainly the result of Tomcat classloader problems, resulting from various dependent classes deployed wrongly in the webapp WEB-INF/lib/ directory, Tomcat lib/ directory, or both. Many of the errors raised as a result of these problems are generic and misleading messages such as 'cannot instantiate class...', 'document error...', etc. (Classloader problems seem to be the root of all evil with things Tomcat.) However, after fixing these problems I am still unable to retrieve the JTA transaction properly from Hibernate 3. I have configured the environment to move the transaction-managed JDBC data source configuration from Tomcat's server.xml into openejb.xml, as follows. JdbcDriver com.mysql.jdbc.Driver JdbcUrl jdbc:mysql://localhost:3306/qadworkflow?autoReconnect=true UserName ... Password ... JtaManaged true InitialSize 0 MaxActive 20 MaxIdle 20 MinIdle 0 MaxWait -1 My hibernate.cfg.xml configuration is as follows (irrelevant settings omitted). java:comp/env/jdbc/LsBpmDS UserTransaction org.hibernate.transaction.JTATransactionFactory org.apache.openejb.hibernate.TransactionManagerLookup With the above I receive a stack overflow error at runtime when attempting to retrieve the JTA transaction. java.lang.StackOverflowError at java.lang.Character.digit(Unknown Source) at java.lang.Character.digit(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at java.text.MessageFormat.makeFormat(Unknown Source) at java.text.MessageFormat.applyPattern(Unknown Source) at java.text.MessageFormat.(Unknown Source) at java.text.MessageFormat.format(Unknown Source) at org.apache.naming.StringManager.getString(StringManager.java:121) at org.apache.naming.StringManager.getString(StringManager.java:144) at org.apache.naming.NamingContext.lookup(NamingContext.java:770) at org.apache.naming.NamingContext.lookup(NamingContext.java:153) at org.apache.naming.SelectorContext.lookup(SelectorContext.java:137) at javax.naming.InitialContext.lookup(Unknown Source) at org.hibernate.transaction.JTATransactionFactory.getUserTransaction(JTATransactionFactory.java:162) at org.hibernate.transaction.JTATransactionFactory.getUserTransaction(JTATransactionFactory.java:172) at org.hibernate.transaction.JTATransactionFactory.getUserTransaction(JTATransactionFactory.java:172) ... Here is an associated nested exception. java.rmi.RemoteException: The bean encountered a non-application exception; nested exception is: java.lang.StackOverflowError at org.apache.openejb.core.transaction.EjbTransactionUtil.handleSystemException(EjbTransactionUtil.java:152) at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:233) at org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:174) at org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:217) at org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:77) at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:281) I have also tried setting the JNDI context factory to the OpenEJB implementation by adding the setting below, but it does not change the error. org.apache.openejb.client.LocalInitialContextFactory The stack overflow error in itself is well-known Hibernate behavior resulting from repeated unsuccessful attempts by Hibernate to retrieve the UserTransaction object. From other postings, I know that Hibernate's JTATran
Re: Transaction Problems with OpenEJB-Hibernate on Tomcat
ed in both server.xml or the webapp's context.xml.) My understanding from other OpenEJB forum postings is that the JNDI name used by OpenEJB from outside an EJB would be 'java:openejb/Resource/LsBpmDS'. However, if I change the connection.datasource property value in hibernate.cfg.xml to ''java:openejb/Resource/LsBpmDS'', I receive a different JNDI lookup error when using either the OpenEJB JNDI context factory or the default. javax.ejb.EJBException: org.hibernate.HibernateException: Could not find datasource at org.apache.openejb.core.stateless.StatelessInstanceManager.getInstance(StatelessInstanceManager.java:212) at org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:165) at org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:217) at org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:77) at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:281) ... I have reviewed Hibernate, OpenEJB, and Tomcat debug logs and can at least verify that the Hibernate settings that I have tried are being used at runtime. However, these logs have not been of much help diagnosing the problem. Please suggest config changes that I made need, or point me to any custom class implementations that might help. Reza Rahman-2 wrote: > > Let me see if I can help here, it'll take me a couple of days, > though...I'm swamped at the moment. I would think David could help too... > > Cheers, > Reza > = > Author, EJB 3 in Action > Expert Group Member, Java EE 6 and EJB 3.1 > Resin EJB 3.1 Lite Container Lead > > > Jacek Laskowski wrote: >> On Mon, Jan 11, 2010 at 4:32 AM, freeway wrote: >> >> >>> To close this message: I have seen many (rather confusing) posts and >>> partial >>> examples regarding the use of the config files persistence.xml, >>> services-jar.xml, and/or openejb-jar.xml files to define data source >>> resources, Hibernate properties, and transaction managers more >>> explicitly >>> inside OpenEJB. However, it seems to me based on other doc I have read >>> that >>> using openejb.xml, ejb-jar.xml, and the native Hibernate files should be >>> enough for a seemingly straightforward case like this one. If this is >>> wrong, please steer me in the right direction. >>> >> >> I'm so glad you're building the stack with OpenEJB, but alas I won't >> be able to help you out with the problem at hand. I hope there're >> people in the mailing list who will share their findings with similar >> configurations and will provide a viable solution. >> >> Jacek >> >> > > > -- View this message in context: http://n4.nabble.com/Transaction-Problems-with-OpenEJB-Hibernate-on-Tomcat-tp1011003p1017047.html Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: Transaction Problems with OpenEJB-Hibernate on Tomcat
Let me see if I can help here, it'll take me a couple of days, though...I'm swamped at the moment. I would think David could help too... Cheers, Reza = Author, EJB 3 in Action Expert Group Member, Java EE 6 and EJB 3.1 Resin EJB 3.1 Lite Container Lead Jacek Laskowski wrote: On Mon, Jan 11, 2010 at 4:32 AM, freeway wrote: To close this message: I have seen many (rather confusing) posts and partial examples regarding the use of the config files persistence.xml, services-jar.xml, and/or openejb-jar.xml files to define data source resources, Hibernate properties, and transaction managers more explicitly inside OpenEJB. However, it seems to me based on other doc I have read that using openejb.xml, ejb-jar.xml, and the native Hibernate files should be enough for a seemingly straightforward case like this one. If this is wrong, please steer me in the right direction. I'm so glad you're building the stack with OpenEJB, but alas I won't be able to help you out with the problem at hand. I hope there're people in the mailing list who will share their findings with similar configurations and will provide a viable solution. Jacek
Re: Transaction Problems with OpenEJB-Hibernate on Tomcat
On Mon, Jan 11, 2010 at 4:32 AM, freeway wrote: > To close this message: I have seen many (rather confusing) posts and partial > examples regarding the use of the config files persistence.xml, > services-jar.xml, and/or openejb-jar.xml files to define data source > resources, Hibernate properties, and transaction managers more explicitly > inside OpenEJB. However, it seems to me based on other doc I have read that > using openejb.xml, ejb-jar.xml, and the native Hibernate files should be > enough for a seemingly straightforward case like this one. If this is > wrong, please steer me in the right direction. I'm so glad you're building the stack with OpenEJB, but alas I won't be able to help you out with the problem at hand. I hope there're people in the mailing list who will share their findings with similar configurations and will provide a viable solution. Jacek -- Jacek Laskowski Notatnik Projektanta Java EE - http://wszystkojawne.pl p.s. Szukam speca/firmy od grafiki/CSS/HTML
Transaction Problems with OpenEJB-Hibernate on Tomcat
ctory(TransactionFactoryFactory.java:79) at org.hibernate.cfg.SettingsFactory.createTransactionFactory(SettingsFactory.java:452) at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:165) at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2101) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1325) at ... Casting exceptions are often indicators of version mismatches within the environment, but here I think that the OpenEJB and Hibernate versions with their dependencies are all compatible. I have modified the application code, primarily package names, in order to upgrade to Hibernate 3 in a minimal way (that is, without reworking the code to remove deprecated methods), but the above error looks like it is in the stack rather than the app. I have not found much on the web to help here. Any suggestions? Another related point is the location of the Hibernate-related JARs and configuration-mapping files mentioned above. I expect that, given that OpenEJB is now managing the transactions and calls to Hibernate as well as the EJBs, the best location to save these JAR files and hibernate.cfg.xml is probably /lib/, rather than in either the application or openejb webapp. However, when testing this way the processing does not even reach the above error, but instead raises the following one. ERROR - The bean instance com.myorg.myapp.myb...@edeea8 threw a system exception:javax.ejb.EJBException: org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml javax.ejb.EJBException: org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml at com.myorg.myapp.MyBean.ejbCreate(MyBean.java:69) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at ... I know that the syntax of hibernate.cfg.xml itself is correct and can be found by Hibernate, given that in the first test it is being parsed correctly by Hibernate and also based on independent XML parser checks. All the Hibernate config files have been updated to reference the Hibernate 3.0 rather than 2.0 DTDs. I am fairly sure that the error is being raised because the mapping files MySQL/*.hbm.xml files referenced inside hibernate.cfg.xml are not being found at runtime. However, I can't find the proper place to put them! They are currently packaged in a JAR file, and I have tried placing this JAR file in /lib/, /lib/, and /WEB-INF/lib/. I have also tried unpacking the MySQL/*.hbm.xml tree into the same directories, with no luck. I was able to pass the parsing error by deploying all the above Hibernate-related JARs both into the application webapp WEB-INF/lib/ directory and in /lib/, along with the JAR that contains the MySQL/*.hbm.xml files; after which I ran into the first Java error mentioned above. I am sure that deploying these JARs in two places at once in the Tomcat environment is a bad idea, but where should they go? To close this message: I have seen many (rather confusing) posts and partial examples regarding the use of the config files persistence.xml, services-jar.xml, and/or openejb-jar.xml files to define data source resources, Hibernate properties, and transaction managers more explicitly inside OpenEJB. However, it seems to me based on other doc I have read that using openejb.xml, ejb-jar.xml, and the native Hibernate files should be enough for a seemingly straightforward case like this one. If this is wrong, please steer me in the right direction. Thx in advance, Fred -- View this message in context: http://n4.nabble.com/Transaction-Problems-with-OpenEJB-Hibernate-on-Tomcat-tp1011003p1011003.html Sent from the OpenEJB User mailing list archive at Nabble.com.