openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Henderson <peter.hender...@starjar.com>
Subject Re: OpenJPA on Tomcat
Date Sun, 17 May 2009 13:53:41 GMT
David,

Thanks for helping, although I don't think this issue is 
HSQLDB related. The persisence.xml file i posted had those 
items commented out. I've attached a cleaned up version [1]

Cheers

Peter.


[1] persistence.xml

<?xml version="1.0"?>
<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="StarjarEnterpriseOpenjpaPU">

 
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
 
<jta-data-source>jdbc/StarjarEnterprise5DS</jta-data-source>

 
<class>com.starjar.starjarenterprise5.domain.AccountCategory</class>
     <exclude-unlisted-classes>true</exclude-unlisted-classes>

     <properties>
       <property name="openjpa.Log" value="DefaultLevel=INFO,
Runtime=ERROR, Tool=ERROR, SQL=ERROR, DataCache=ERROR"/>

       <property name="openjpa.AutoDetach" value="close, 
commit"/>
       <property name="openjpa.DetachState" 
value="loaded(DetachedStateField=false, 
DetachedStateManager=false)"/>
     </properties>
   </persistence-unit>
</persistence>




David Beer wrote:
> On Sun, 17 May 2009 12:19:19 +0100
> Peter Henderson <peter.henderson@starjar.com> wrote:
> 
>> I am having some problems getting OpenJPA to work under 
>> tomcat 6.0.18.
>>
>> I've created a data source in tomcat/conf/context.xml [1]
>> Referenced the data source in my web.xml [2]
>> Tested using the data source in a servlet at start up [3] 
>> which should prove my data source has been configured correctly.
>>
>> Yet when I try to initialize an entity manager factor using 
>> my persistence.xml[4] I get an exception [5]
>>
>>
>> So what have I missed?
>>
>>
>> Peter.
>>
>>
>>
>>
>>
>>
>>
>>
>> [1] tomcat/conf/context.xml
>>
>> <Context>
>>
>>      <!-- Default set of monitored resources -->
>>      <WatchedResource>WEB-INF/web.xml</WatchedResource>
>> 	
>>
>>
>>      <Resource name="jdbc/StarjarEnterprise5DS" auth="Container"
>> 		  type="javax.sql.DataSource" 
>> driverClassName="org.postgresql.Driver"
>> 		  url="jdbc:postgresql://127.0.0.1:5432/mydb"
>> 		  username="user" password="password" maxActive="20" 
>> maxIdle="10" maxWait="-1"/>
>>
>>
>> </Context>
>>
>>
>>
>> [2] web.xml
>> <web-app version="2.5" 
>> xmlns="http://java.sun.com/xml/ns/javaee" 
>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
>> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
>> http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
>>
>>
>>      <display-name>Starjar Enterprise</display-name>
>>
>>     <!-- servlet and mappings here -->
>>
>>    <resource-ref>
>>        <description>Starjar Datasouce Connection</description>
>>        <res-ref-name>jdbc/StarjarEnterprise5DS</res-ref-name>
>>        <res-type>javax.sql.DataSource</res-type>
>>        <res-auth>Container</res-auth>
>>    </resource-ref>
>>
>> </web-app>
>>
>>
>>
>> [3] Test code
>> Context initCtx = null; Context envCtx;
>>
>> DataSource ds = null;
>> try {
>>      initCtx = new InitialContext();
>>      envCtx = (Context) initCtx.lookup("java:comp/env");
>>      ds = (DataSource) 
>> envCtx.lookup("jdbc/StarjarEnterprise5DS");
>>      System.out.println("Got DATA SOURCE VIA " + ds);
>>      log.error("++++++++++++Got DATA SOURCE VIA JNDI " + ds);
>>
>>      // Test out the datasource.
>>      Connection con = ds.getConnection();
>>      //PreparedStatement ps = con.prepareStatement("SELECT 
>> 'Hello World'");
>>      PreparedStatement ps = con.prepareStatement("SELECT * 
>> from organization");
>>      ResultSet rs = ps.executeQuery();
>>      while (rs.next()) {
>>          String msg = rs.getString(1);
>>          log.info("Ran query got message " + msg);
>>      }
>>      rs.close();
>>      ps.close();
>>      con.close();
>>
>>
>> } catch (Exception ex) {
>>      log.error("+++++++++++++++++++++Did not get DS", ex);
>>      ex.printStackTrace();
>> }
>>
>>
>>
>>
>> [4] My persistence.xml
>> <?xml version="1.0"?>
>> <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="StarjarEnterpriseOpenjpaPU">
>>
>>  
>> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>> <!-- 
>> <jta-data-source>jdbc/StarjarEnterprise5DS</jta-data-source> -->
>>  
>> <jta-data-source>java:comp/env/jdbc/StarjarEnterprise5DS</jta-data-source>
>>
>> <!-- snip class entries -->
>>      <properties>
>>        <property name="openjpa.Log" value="DefaultLevel=INFO,
>> Runtime=ERROR, Tool=ERROR, SQL=ERROR, DataCache=ERROR"/>
>>
>>        <property name="openjpa.AutoDetach" value="close, 
>> commit"/>
>>        <!--property name="openjpa.DetachState" value="all"/-->
>>        <property name="openjpa.DetachState" 
>> value="loaded(DetachedStateField=false, 
>> DetachedStateManager=false)"/>
>>
>>        <!--property name="openjpa.AutoDetach" value="close"/-->
>>
>>        <!--<property name="openjpa.ConnectionDriverName" 
>> value="org.postgresql.Driver"/> -->
>>
>>
>>
>>
>> <!--
>>        <property name="openjpa.ConnectionURL" 
>> value="jdbc:hsqldb:tutorial_database"/>
>>        <property name="openjpa.ConnectionDriverName" 
>> value="org.hsqldb.jdbcDriver"/>
>>        <property name="openjpa.ConnectionUserName" value="sa"/>
>>        <property name="openjpa.ConnectionPassword" value=""/>
>>        <property name="openjpa.Log" 
>> value="DefaultLevel=WARN, Tool=INFO"/>
>> -->
>>      </properties>
>>
>>
>>
>>
>>
>> [5] The exception
>> <openjpa-1.2.1-r752877:753278 fatal user error> 
>> org.apache.openjpa.persistence.ArgumentException: A JDBC 
>> Driver or DataSource class name must be specified in the 
>> ConnectionDriverName property.
>> 	at 
>> org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:74)
>> 	at 
>> org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory(JDBCConfigurationImpl.java:784)
>> 	at 
>> org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDBDictionaryInstance(JDBCConfigurationImpl.java:561)
>> 	at 
>> org.apache.openjpa.jdbc.meta.MappingRepository.endConfiguration(MappingRepository.java:1265)
>> 	at 
>> org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:505)
>> 	at 
>> org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:430)
>> 	at 
>> org.apache.openjpa.lib.conf.PluginValue.instantiate(PluginValue.java:103)
>> 	at 
>> org.apache.openjpa.conf.MetaDataRepositoryValue.instantiate(MetaDataRepositoryValue.java:68)
>> 	at 
>> org.apache.openjpa.lib.conf.ObjectValue.instantiate(ObjectValue.java:83)
>> 	at 
>> org.apache.openjpa.conf.OpenJPAConfigurationImpl.newMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:863)
>> 	at 
>> org.apache.openjpa.conf.OpenJPAConfigurationImpl.getMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:854)
>> 	at 
>> org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:638)
>> 	at 
>> org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:183)
>> 	at 
>> org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:142)
>> 	at 
>> org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:192)
>> 	at 
>> org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:145)
>> 	at 
>> org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:56)
>> 	at 
>> com.starjar.starjarenterprise5.remote_impl.EntityManagerServlet.getEntityManager(EntityManagerServlet.java:119)
>> 	at 
>> com.starjar.starjarenterprise5.remote_impl.EntityManagerServlet.initializeEntityManger(EntityManagerServlet.java:102)
>> 	at 
>> com.starjar.starjarenterprise5.remote_impl.EntityManagerServlet.init(EntityManagerServlet.java:141)
>> 	at 
>> org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172)
>> 	at 
>> org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:992)
>> 	at 
>> org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4058)
>> 	at 
>> org.apache.catalina.core.StandardContext.start(StandardContext.java:4371)
>> 	at 
>> org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
>> 	at 
>> org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
>> 	at 
>> org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
>> 	at 
>> org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:830)
>> 	at 
>> org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:719)
>> 	at 
>> org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:490)
>> 	at 
>> org.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)
>> 	at 
>> org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
>> 	at 
>> org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
>> 	at 
>> org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
>> 	at 
>> org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
>> 	at 
>> org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
>> 	at 
>> org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
>> 	at 
>> org.apache.catalina.core.StandardService.start(StandardService.java:516)
>> 	at 
>> org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
>> 	at 
>> org.apache.catalina.startup.Catalina.start(Catalina.java:578)
>> 	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.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
>> 	at 
>> org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
>> 17-May-2009 12:02:18 
>> org.apache.catalina.core.StandardContext loadOnStartup
>>
>>
>>
>>
>>
> 
> Hi Peter
> 
> I think your problem may lie in the persistece.xml file the Connection
> URL[1] either doesn't match properly or OpenJpa can't find the correct
> jar file with the folder in.
> 
> [1] http://hsqldb.org/web/hsqlDocsFrame.html
> 
> David
> 


-- 
Peter Henderson
Director Starjar Limited.

Mobile: +44 (0) 778 233 8645
Email: peter.henderson@starjar.com
Web: www.starjar.com


Mime
View raw message