geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Jencks <david_jen...@yahoo.com>
Subject Re: Geronimo with openjpa (and DataSource lookups)
Date Tue, 01 Dec 2009 16:16:01 GMT
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-source>jdbc/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-source>jdbc/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:groupId>TestService</dep:groupId>
>            <dep:artifactId>rest</dep:artifactId>
>            <dep:version>1.0</dep:version>
>            <dep:type>car</dep:type>
>        </dep:moduleId>
>        <dep:dependencies>
>            <dep:dependency>
>                <dep:groupId>console.dbpool</dep:groupId>
>                <dep:artifactId>jdbc_db</dep:artifactId>
>            </dep:dependency>
>        </dep:dependencies>
>    </dep:environment>
>    <web:context-root>/test</web:context-root>
>
>    <name:resource-ref>
>      <name:ref-name>jdbc/db</name:ref-name>
>      <name:resource-link>jdbc/db</name:resource-link>
>    </name:resource-ref>
> </web:web-app>
>
> web.xml:
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE web-app PUBLIC
> "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
> "http://java.sun.com/dtd/web-app_2_3.dtd" >
>
> <web-app>
>    <display-name>Test Apache Wink</display-name>
>    <servlet>
>        <servlet-name>WINK-Restful</servlet-name>
>
> <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</ 
> servlet-class>
>        <init-param>
>            <param-name>javax.ws.rs.Application</param-name>
>            <param-value>simple.test.WinkApplication</param-value>
>        </init-param>
>        <load-on-startup>1</load-on-startup>
>    </servlet>
>    <servlet-mapping>
>        <servlet-name>WINK-Restful</servlet-name>
>        <url-pattern>/rest/*</url-pattern>
>    </servlet-mapping>
>
>    <resource-ref>
>    <res-ref-name>jdbc/db</res-ref-name>
>    <res-type>javax.sql.DataSource</res-type>
>    <res-auth>Container</res-auth>
>    <res-sharing-scope>Shareable</res-sharing-scope>
>  </resource-ref>
> </web-app>
>
> geronimo-web.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:groupId>TestService</dep:groupId>
>            <dep:artifactId>rest</dep:artifactId>
>            <dep:version>1.0</dep:version>
>            <dep:type>car</dep:type>
>        </dep:moduleId>
>        <dep:dependencies>
>            <dep:dependency>
>                <dep:groupId>console.dbpool</dep:groupId>
>                <dep:artifactId>jdbc_db</dep:artifactId>
>            </dep:dependency>
>        </dep:dependencies>
>    </dep:environment>
>    <web:context-root>/test</web:context-root>
>
>    <name:resource-ref>
>      <name:ref-name>jdbc/db</name:ref-name>
>      <name:resource-link>jdbc/db</name:resource-link>
>    </name:resource-ref>
> </web:web-app>
>
> persistence.xml:
> <?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="test.jpa">
> 		<jta-data-source>jdbc/db</jta-data-source>
> <!--	<non-jta-data-source>jdbc/db</non-jta-data-source>-->
> 		<class>simple.test.jpa.AuthEvent</class>
>
> 		<properties>
> <!--		<property name="openjpa.ConnectionDriverName"
> value="oracle.jdbc.driver.OracleDriver"></property>-->
> <!--		<property name="openjpa.ConnectionURL"
> value="jdbc:oracle:thin:@localhost:1521:Database"></property>-->
> <!--		<property name="openjpa.ConnectionUserName"
> value="cumbers"></property>-->
> <!--		<property name="openjpa.ConnectionPassword"
> value="passw0rd"></property>-->
> 			<property name="openjpa.Log" value="DefaultLevel=TRACE" />
> 		</properties>
> 	</persistence-unit>
> </persistence>
>
> console.dbpool plan.xml file:
> <?xml version="1.0" encoding="UTF-8"?>
> <connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/ 
> connector-1.2">
>    <dep:environment
> xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.2">
>        <dep:moduleId>
>            <dep:groupId>console.dbpool</dep:groupId>
>            <dep:artifactId>jdbc_db</dep:artifactId>
>            <dep:version>1.0</dep:version>
>            <dep:type>rar</dep:type>
>        </dep:moduleId>
>        <dep:dependencies>
>            <dep:dependency>
>                <dep:groupId>oracle</dep:groupId>
>                <dep:artifactId>oracle</dep:artifactId>
>                <dep:version>11</dep:version>
>                <dep:type>jar</dep:type>
>            </dep:dependency>
>        </dep:dependencies>
>    </dep:environment>
>    <resourceadapter>
>        <outbound-resourceadapter>
>            <connection-definition>
>
> <connectionfactory-interface>javax.sql.DataSource</connectionfactory- 
> interface>
>                <connectiondefinition-instance>
>                    <name>jdbc/db</name>
>                    <config-property-setting
> name="ConnectionURL">jdbc:oracle:thin:@localhost:1521:Database</ 
> config-property-setting>
>                    <config-property-setting
> name="UserName">cumbers</config-property-setting>
>                    <config-property-setting
> name="Password">passw0rd</config-property-setting>
>                    <config-property-setting
> name="Driver">oracle.jdbc.OracleDriver</config-property-setting>
>
>                    <connectionmanager>
>                        <local-transaction/>
>                        <single-pool>
>                            <max-size>10</max-size>
>                            <min-size>0</min-size>
>                            <match-one/>
>                        </single-pool>
>                    </connectionmanager>
>                </connectiondefinition-instance>
>            </connection-definition>
>        </outbound-resourceadapter>
>    </resourceadapter>
> </connector>
>
> openJPA trace:
> 0  test.jpa  TRACE  [http-0.0.0.0-8443-1] openjpa.Runtime - Setting  
> the
> following properties from
> "file:/opt/IBM/WebSphere/AppServerCommunityEdition/repository/com/ 
> ibm/test/rest/1.0/rest-1.0.car/WEB-INF/classes/META-INF/ 
> persistence.xml"
> into configuration: {openjpa.Id=test.jpa,  
> openjpa.Log=DefaultLevel=TRACE,
> openjpa.MetaDataFactory=jpa(Types=simple.test.jpa.AuthEvent),
> openjpa.BrokerFactory=jdbc, openjpa.ConnectionFactoryName=jdbc/db}
> 6  test.jpa  INFO   [http-0.0.0.0-8443-1] openjpa.Runtime - Starting  
> OpenJPA
> 1.2.1
> 7  test.jpa  TRACE  [http-0.0.0.0-8443-1] openjpa.Runtime -  
> Properties:
> openjpa.RestoreState: immutable
> openjpa.Sequence: table
> openjpa.jdbc.SQLFactory: default
> openjpa.BrokerImpl: default
> openjpa.ConnectionFactoryName: jdbc/db
> openjpa.Id: test.jpa
> openjpa.QueryCache: true
> openjpa.ReadLockLevel: read
> openjpa.LockManager: version
> openjpa.jdbc.UpdateManager: default
> openjpa.NontransactionalRead: true
> openjpa.DynamicDataStructs: false
> openjpa.RetainState: true
> openjpa.DetachState: loaded
> openjpa.jdbc.MappingDefaults: jpa
> openjpa.ClassResolver: default
> openjpa.AutoDetach:
> openjpa.TransactionMode: local
> openjpa.FlushBeforeQueries: true
> openjpa.jdbc.TransactionIsolation: default
> openjpa.jdbc.SchemaFactory: dynamic
> openjpa.MetaDataRepository: default
> openjpa.RuntimeUnenhancedClasses: supported
> openjpa.RefreshFromDataCache: false
> openjpa.jdbc.DriverDataSource: simple
> openjpa.DataCache: false
> openjpa.WriteLockLevel: write
> openjpa.MetaDataFactory: jpa(Types=simple.test.jpa.AuthEvent)
> openjpa.LockTimeout: -1
> openjpa.jdbc.ResultSetType: forward-only
> openjpa.ManagedRuntime: auto
> openjpa.jdbc.QuerySQLCache: true
> openjpa.jdbc.LRSSize: query
> openjpa.QueryCompilationCache: true
> openjpa.Log: DefaultLevel=TRACE
> openjpa.jdbc.EagerFetchMode: parallel
> openjpa.Optimistic: true
> openjpa.SavepointManager: in-mem
> openjpa.Multithreaded: false
> openjpa.ProxyManager: default
> openjpa.OrphanedKeyAction: log
> openjpa.FetchBatchSize: -1
> openjpa.AutoClear: datastore
> openjpa.jdbc.Schemas:
> openjpa.jdbc.SynchronizeMappings: false
> openjpa.ConnectionFactoryMode: local
> openjpa.RetryClassRegistration: false
> openjpa.Compatibility: default
> openjpa.MaxFetchDepth: -1
> openjpa.InverseManager: false
> openjpa.jdbc.FetchDirection: forward
> openjpa.jdbc.SubclassFetchMode: join
> openjpa.FetchGroups: default
> openjpa.IgnoreChanges: false
> openjpa.DataCacheTimeout: -1
> openjpa.NontransactionalWrite: true
> openjpa.ConnectionRetainMode: on-demand
> openjpa.EntityManagerFactory: default
> openjpa.BrokerFactory: jdbc
> openjpa.DataCacheManager: default
> 8  test.jpa  TRACE  [http-0.0.0.0-8443-1] openjpa.Runtime - No cache
> marshaller found for id  
> org.apache.openjpa.conf.MetaDataCacheMaintenance.
> 88  test.jpa  TRACE  [http-0.0.0.0-8443-1] openjpa.MetaData - Using  
> metadata
> factory
> "org 
> .apache.openjpa.persistence.jdbc.PersistenceMappingFactory@1db21db2".
> 106  test.jpa  TRACE  [http-0.0.0.0-8443-1] openjpa.jdbc.JDBC -  
> OpenJPA will
> now connect to the database to attempt to determine what type of  
> database
> dictionary to use. You may prevent this connection in the future by  
> setting
> your openjpa.jdbc.DBDictionary configuration property to the  
> appropriate
> value for your database (see the documentation for available values).
>
> -- 
> View this message in context: http://old.nabble.com/Geronimo-with-openjpa-%28and-DataSource-lookups%29-tp26532836s134p26590541.html
> Sent from the Apache Geronimo - Users mailing list archive at  
> Nabble.com.
>


Mime
View raw message