Re: Geronimo with openjpa (and DataSource lookups)
I have spent the last few days trying to understand how the daytrader app differs from what I have implemented and have not been successful at all. So I am going to document fully what I am doing in the hope that some bright spark points out the error of my ways! I am using Eclipse and WAS CE (which from what I understand is Geronimo with some extra bits). I am developing a REST service using the Apache Wink library, which uses JPA to connect to a database. The application will work, but only if I use property tags in the persitence.xml to define the required DB connection for JPA. If I just have the jta-data-sourcejdbc/db/jta-data-source line, I get the following error: openjpa-1.2.1-r2180:4612 fatal user error org.apache.openjpa.persistence.ArgumentException: A JDBC Driver or DataSource class name must be specified in the ConnectionDriverName property. org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:74) org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory(JDBCConfigurationImpl.java:784) org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDBDictionaryInstance(JDBCConfigurationImpl.java:561) org.apache.openjpa.jdbc.meta.MappingRepository.endConfiguration(MappingRepository.java:1265) org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:505) org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:430) org.apache.openjpa.lib.conf.PluginValue.instantiate(PluginValue.java:103) org.apache.openjpa.conf.MetaDataRepositoryValue.instantiate(MetaDataRepositoryValue.java:68) org.apache.openjpa.lib.conf.ObjectValue.instantiate(ObjectValue.java:83) org.apache.openjpa.conf.OpenJPAConfigurationImpl.newMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:863) org.apache.openjpa.conf.OpenJPAConfigurationImpl.getMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:854) org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:638) org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:183) org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:142) org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:192) org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:145) org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:56) simple.test.db.TransferResource.clinit(TransferResource.java:46) Where the relevant lines from the TransferResource class are: // Get the factory defined in persistence.xml as test.jpa private static final EntityManagerFactory emFactory = Persistence.createEntityManagerFactory(test.jpa); // Get an Entity Manager from factory. EXCEPTION THROWN ON NEXT LINE private static final EntityManager em = emFactory.createEntityManager(); If I use the properties which have been commented out in the persitence.xml, then the servicve works. If I alter the name in the jta-data-sourcejdbc/db/jta-data-source from jdbc/db to wibble then I cannot deploy my code because wibble does not exist. I am at a loss for how to solve this. Ideally my code will be a closed WAR file that does not require the end user to unpack, edit some properties, repack and then deploy, they should be able to use the JNDI object for the database. Below is the structure of the web application as deployed to the web server. I also include the openJPA trace in case someone finds it useful. Any help is very much appreciated!!! META-INF |--plan.xml WEB-INF |--web.xml |--geronimo-web.xml |--classes | |--META-INF |--persistence.xml plan.xml: ?xml version=1.0 encoding=UTF-8? web:web-app xmlns:app=http://geronimo.apache.org/xml/ns/j2ee/application-2.0; xmlns:client=http://geronimo.apache.org/xml/ns/j2ee/application-client-2.0; xmlns:conn=http://geronimo.apache.org/xml/ns/j2ee/connector-1.2; xmlns:dep=http://geronimo.apache.org/xml/ns/deployment-1.2; xmlns:ejb=http://openejb.apache.org/xml/ns/openejb-jar-2.2; xmlns:name=http://geronimo.apache.org/xml/ns/naming-1.2; xmlns:pers=http://java.sun.com/xml/ns/persistence; xmlns:pkgen=http://openejb.apache.org/xml/ns/pkgen-2.1; xmlns:sec=http://geronimo.apache.org/xml/ns/security-2.0; xmlns:web=http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1; dep:environment dep:moduleId dep:groupIdTestService/dep:groupId dep:artifactIdrest/dep:artifactId dep:version1.0/dep:version dep:typecar/dep:type /dep:moduleId dep:dependencies dep:dependency
Re: Geronimo with openjpa (and DataSource lookups)
The code private static final EntityManagerFactory emFactory = Persistence.createEntityManagerFactory(test.jpa); is how you use jpa in a non-managed environment, so it won't work with the managed jpa support in geronimo, as you are experiencing. I don't think you explain how the control flow gets to this code. What I would suggest is that you have an ee component such as an ejb that has the entitymanager injected and then pass the entitymanager to the wink (?) code that uses it. Don't use static variables and don't store the em in a field unless each call gets its own copy of the object (like stateless session beans). If you want to avoid ejbs get an EntityManagerFactory instead. hope this helps david jencks On Dec 1, 2009, at 3:46 AM, cumbers wrote: I have spent the last few days trying to understand how the daytrader app differs from what I have implemented and have not been successful at all. So I am going to document fully what I am doing in the hope that some bright spark points out the error of my ways! I am using Eclipse and WAS CE (which from what I understand is Geronimo with some extra bits). I am developing a REST service using the Apache Wink library, which uses JPA to connect to a database. The application will work, but only if I use property tags in the persitence.xml to define the required DB connection for JPA. If I just have the jta-data-sourcejdbc/db/jta-data-source line, I get the following error: openjpa-1.2.1-r2180:4612 fatal user error org.apache.openjpa.persistence.ArgumentException: A JDBC Driver or DataSource class name must be specified in the ConnectionDriverName property. org .apache .openjpa .jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java: 74) org .apache .openjpa .jdbc .conf .JDBCConfigurationImpl .createConnectionFactory(JDBCConfigurationImpl.java:784) org .apache .openjpa .jdbc .conf .JDBCConfigurationImpl .getDBDictionaryInstance(JDBCConfigurationImpl.java:561) org .apache .openjpa .jdbc.meta.MappingRepository.endConfiguration(MappingRepository.java: 1265) org .apache .openjpa .lib.conf.Configurations.configureInstance(Configurations.java:505) org .apache .openjpa .lib.conf.Configurations.configureInstance(Configurations.java:430) org.apache.openjpa.lib.conf.PluginValue.instantiate(PluginValue.java: 103) org .apache .openjpa .conf .MetaDataRepositoryValue.instantiate(MetaDataRepositoryValue.java:68) org.apache.openjpa.lib.conf.ObjectValue.instantiate(ObjectValue.java: 83) org .apache .openjpa .conf .OpenJPAConfigurationImpl .newMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:863) org .apache .openjpa .conf .OpenJPAConfigurationImpl .getMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:854) org .apache .openjpa .kernel .AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:638) org .apache .openjpa .kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java: 183) org .apache .openjpa .kernel .DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:142) org .apache .openjpa .persistence .EntityManagerFactoryImpl .createEntityManager(EntityManagerFactoryImpl.java:192) org .apache .openjpa .persistence .EntityManagerFactoryImpl .createEntityManager(EntityManagerFactoryImpl.java:145) org .apache .openjpa .persistence .EntityManagerFactoryImpl .createEntityManager(EntityManagerFactoryImpl.java:56) simple.test.db.TransferResource.clinit(TransferResource.java:46) Where the relevant lines from the TransferResource class are: // Get the factory defined in persistence.xml as test.jpa private static final EntityManagerFactory emFactory = Persistence.createEntityManagerFactory(test.jpa); // Get an Entity Manager from factory. EXCEPTION THROWN ON NEXT LINE private static final EntityManager em = emFactory.createEntityManager(); If I use the properties which have been commented out in the persitence.xml, then the servicve works. If I alter the name in the jta-data-sourcejdbc/db/jta-data-source from jdbc/db to wibble then I cannot deploy my code because wibble does not exist. I am at a loss for how to solve this. Ideally my code will be a closed WAR file that does not require the end user to unpack, edit some properties, repack and then deploy, they should be able to use the JNDI object for the database. Below is the structure of the web application as deployed to the web server. I also include the openJPA trace in case someone finds it useful. Any help is very much appreciated!!! META-INF |--plan.xml WEB-INF |--web.xml |--geronimo-web.xml |--classes | |--META-INF |--persistence.xml plan.xml: ?xml version=1.0 encoding=UTF-8? web:web-app xmlns:app=http://geronimo.apache.org/xml/ns/j2ee/application-2.0; xmlns:client=http://geronimo.apache.org/xml/ns/j2ee/application-client-2.0
Re: Geronimo with openjpa (and DataSource lookups)
In Java EE web tier, you can inject jpa resources in the objects managed by container, such as servlets, ServletContextListener, JSF beans, and etc. About the sample code. you can refer to http://java.sun.com/javaee/5/docs/tutorial/doc/bnbrm.html. Forrest
Re: Geronimo with openjpa (and DataSource lookups)
The datasource module needs to be listed as a dependency of the war module if they are deployed separately. Single-valued component search in geronimo follows the directed acyclic graph of dependencies so you can deploy lots of datasources named jdbc/db in different modules yet still get the one you want in your app by specifying the module with the right one as a dependency. thanks david jencks On Nov 26, 2009, at 9:44 AM, cumbers wrote: I am looking for someone to put me out of my geronimo/openpa misery. I have an application that I can deploy to Geronimo (2.1.1.3) that uses openjpa where the properties inside the persistence.xml are explicitly defined like so: properties property name=openjpa.ConnectionDriverName value=oracle.jdbc.driver.OracleDriver/property property name=openjpa.ConnectionURL value=jdbc:oracle:thin:@localhost:1521:DB/property property name=openjpa.ConnectionUserName value=dbuser/property property name=openjpa.ConnectionPassword value=passw0rd/property /properties However this app is going to be deployed by lots of users, and ideally I would like to ship a war file, and direct users to create a JNDI object that they define and then openjpa uses this. Simply defining the JNDI datasource connection within Geronimo, and using the reference in the jta-data-sourcejdbc/db/jta-data-source or non-jta-data-sourcejdbc/db/non-jta-data-source does not appear to work, and I get the following error message when I try and create an EntityManager: openjpa-1.2.1-r2180:4612 fatal user error org.apache.openjpa.persistence.ArgumentException: A JDBC Driver or DataSource class name must be specified in the ConnectionDriverName property. After 3 days on google, I found this page: http://cwiki.apache.org/GMOxDOC21/datasource-connectionfactory-mdb-and-jpa.html which suggests that: Although many other servers use jndi to define the meaning of the jta-data-source and non-jta-data-source geronimo does not. These are not jndi names in any way but must match the name specified in the connector plan. OK so using the jndi object name directly does not seem to be supported. However the name in the resourceadapter of the plan.xml IS jdbc/db and so I think this should work. Here is the relevant snippet from my plan.xml as created when I define a JDBC datasource using Geronimo. resourceadapter outbound-resourceadapter connection-definition connectionfactory-interfacejavax.sql.DataSource/connectionfactory- interface connectiondefinition-instance namejdbc/db/name I have run out of ideas on how I can make this work, and would be massively appreciative if anyone can shed some light on why this is not working. If you think you need more information please let me know! Cheers Rich -- View this message in context: http://old.nabble.com/Geronimo-with-openjpa-%28and-DataSource-lookups%29-tp26532836s134p26532836.html Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.
Re: Geronimo with openjpa (and DataSource lookups)
Hi, You can have the daytrader sample as an example for how to use defined datasource in persistence.xml. http://svn.apache.org/repos/asf/geronimo/daytrader/trunk/ If still not successful, pls try to describe your deployment steps and related exceptions. Forrest