You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Håkon Sagehaug <Ha...@bccs.uib.no> on 2008/11/03 15:22:45 UTC
Using datasource from tomcat with openjpa
Hi all,
I've got a axis2 web service that is deployed in tomcat and talk to a
database using openjpa. This works fine when I just use the persistent xml
to configure my db connection, but now I want to use tomcat to configure the
datasource. Here is my set-up
persistent.xml
<persistence-unit name="MyOpenJPa" transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<class>demo.hibernate.MyPerson</class>
<properties>
<property name="openjpa.ConnectionFactoryName"
value="java:comp/env/jdbc/workflowdb" />
<property name="openjpa.Log" value="DefaultLevel=INFO,
Tool=INFO" />
<property name="openjpa.Sequence"
value="table(Table=OPENJPA_SEQUENCE_TABLE, Increment=1)"/>
</properties>
</persistence-unit>
In tomcat's service xml I've got this
<Resource name="jdbc/workflowdb" auth="Container"
type="javax.sql.DataSource"
maxActive="5" maxIdle="5" maxWait="10000"
username="name" password="password"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://hostname/Workflows"/>
I tried to put it into the <GlobalNamingResources> tag and inside a
<Context> tag using the axis2 as path, but I always get this error back
A JDBC Driver or DataSource class name must be specified in the
ConnectionDriverName property.
Does anyone have a good tip on how to get this to work??
cheers, Håkon
--
Håkon Sagehaug, Software Developer
Parallab, Bergen Center for Computational Science (BCCS)
UNIFOB AS (University of Bergen Research Company)
Re: Using datasource from tomcat with openjpa
Posted by Håkon Sagehaug <Ha...@bccs.uib.no>.
Hi
This is not an issue, I had a wrong service.xml file, so now everything is
fine, but thanks for all the help
Håkon
2008/11/12 Ognjen Blagojevic <og...@etf.bg.ac.rs>
> If this is still the issue, here is my config (Tomcat 6.0.13, Axis 1.3,
> OpenJPA 1.2.0), very similar to what Jeremy posted earlier. The only
> difference I see is <provider> tag in persistence.xml.
>
> --- context.xml ---
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <Context docBase="axis2" debug="5" reloadable="true" allowLinking="true">
>
> <Resource name="jdbc/dbserver" auth="Container"
> type="javax.sql.DataSource"
> maxActive="7"
> maxIdle="3"
> maxWait="10000"
> testWhileIdle="true"
> timeBetweenEvictionRunsMillis="10000"
> minEvictableIdleTimeMillis="60000"
> username="un" password="pw"
> driverClassName="org.postgresql.Driver"
> url="jdbc:postgresql://db.company.com/dbname"/>
>
> </Context>
> ---------------
>
> --- persistence.xml ---
> <?xml version="1.0" encoding="UTF-8"?>
> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance" version="1.0"
> xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
> http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
> <persistence-unit name="testPu">
>
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>
> <jta-data-source>java:comp/env/jdbc/dbserver</jta-data-source>
>
> <class>com.company.Entity1</class>
> <!-- ... -->
>
> </persistence-unit>
> </persistence>
> ---------------
>
> -Ognjen
>
>
> Håkon Sagehaug wrote:
>
>> Thanks so much for the help, now it works for the serlvet, so just trying
>> to
>> get it to work for the web service also and I'll be a happy guy
>>
>
>
--
Håkon Sagehaug, Software Developer
Parallab, Bergen Center for Computational Science (BCCS)
UNIFOB AS (University of Bergen Research Company)
Re: Using datasource from tomcat with openjpa
Posted by Ognjen Blagojevic <og...@etf.bg.ac.rs>.
If this is still the issue, here is my config (Tomcat 6.0.13, Axis 1.3,
OpenJPA 1.2.0), very similar to what Jeremy posted earlier. The only
difference I see is <provider> tag in persistence.xml.
--- context.xml ---
<?xml version="1.0" encoding="ISO-8859-1"?>
<Context docBase="axis2" debug="5" reloadable="true" allowLinking="true">
<Resource name="jdbc/dbserver" auth="Container"
type="javax.sql.DataSource"
maxActive="7"
maxIdle="3"
maxWait="10000"
testWhileIdle="true"
timeBetweenEvictionRunsMillis="10000"
minEvictableIdleTimeMillis="60000"
username="un" password="pw"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://db.company.com/dbname"/>
</Context>
---------------
--- persistence.xml ---
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="testPu">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>java:comp/env/jdbc/dbserver</jta-data-source>
<class>com.company.Entity1</class>
<!-- ... -->
</persistence-unit>
</persistence>
---------------
-Ognjen
Håkon Sagehaug wrote:
> Thanks so much for the help, now it works for the serlvet, so just trying to
> get it to work for the web service also and I'll be a happy guy
Re: Using datasource from tomcat with openjpa
Posted by Håkon Sagehaug <Ha...@bccs.uib.no>.
Hi
Thanks so much for the help, now it works for the serlvet, so just trying to
get it to work for the web service also and I'll be a happy guy
cheers, Håkon
2008/11/5 Jeremy Bauer <te...@gmail.com>
> Hi Håkon,
>
> Try defining a non-jta data source in your persistence.xml. That should
> correct the problem. You can even use the same data source as you've
> defined for your jta-data-source name.
>
> ex:
> <non-jta-data-source>java:comp/env/jdbc/workflowdb</non-jta-data-source>
>
> -Jeremy
>
> On Wed, Nov 5, 2008 at 7:08 AM, Håkon Sagehaug
> <Ha...@bccs.uib.no>wrote:
>
> > Hi
> >
> > I tried to get it to just work on a servlet and have more success here,
> but
> > have now this problem, when I want to get the transaction in my servlet
> > like
> > this I
> >
> > em.getTransaction().begin();
> >
> > and error is thrown
> >
> > Caused by: java.sql.SQLException: Unable to obtain a TransactionManager
> > using null.
> > at
> >
> >
> org.apache.openjpa.jdbc.kernel.TableJDBCSeq.allocateSequence(TableJDBCSeq.java:419)
> > at
> >
> >
> org.apache.openjpa.jdbc.kernel.TableJDBCSeq.nextInternal(TableJDBCSeq.java:290)
> > at
> >
> >
> org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq.next(AbstractJDBCSeq.java:60)
> > ... 33 more
> > Caused by: javax.transaction.NotSupportedException: Unable to obtain a
> > TransactionManager using null.
> > at
> >
> >
> org.apache.openjpa.ee.AutomaticManagedRuntime.doNonTransactionalWork(AutomaticManagedRuntime.java:306)
> > at
> >
> >
> org.apache.openjpa.jdbc.kernel.TableJDBCSeq.allocateSequence(TableJDBCSeq.java:415)
> > ... 35 more
> > Caused by: <openjpa-1.2.0-r422266:683325 fatal user error>
> > org.apache.openjpa.util.InvalidStateException: Could not perform
> automatic
> > lookup of EJB container's javax.transaction.TransactionManager
> > implementation. Please ensure that you are running the application from
> > within an EJB 1.1 compliant EJB container, and then set the
> > org.apache.openjpa.ManagedRuntime property to
> > at
> >
> >
> org.apache.openjpa.ee.AutomaticManagedRuntime.getTransactionManager(AutomaticManagedRuntime.java:250)
> > at
> >
> >
> org.apache.openjpa.ee.AutomaticManagedRuntime.doNonTransactionalWork(AutomaticManagedRuntime.java:304)
> > ... 36 more
> > Caused by: javax.naming.NameNotFoundException: Name
> > TransactionSynchronizationRegistry is not bound in this Context
> > at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
> > at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
> > at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
> > at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
> > at org.apache.naming.SelectorContext.lookup(SelectorContext.java:137)
> > at javax.naming.InitialContext.lookup(InitialContext.java:392)
> > at
> >
> >
> org.apache.openjpa.ee.RegistryManagedRuntime.getTransactionManager(RegistryManagedRuntime.java:61)
> > at
> >
> >
> org.apache.openjpa.ee.AutomaticManagedRuntime.getTransactionManager(AutomaticManagedRuntime.java:168)
> > ... 37 more
> >
> >
> > It works fine when I just want to do a db lookup and not involve the
> > transaction manager. Do I need to specify a transaction manager in tomcat
> > as
> > I did with the datasource?
> >
> > cheers, håkon
> >
> >
> > 2008/11/5 Håkon Sagehaug <Ha...@bccs.uib.no>
> >
> > > Hi all,
> > >
> > > I don't know exactly my problems lies, but think it may be in axis or
> I'm
> > > not sure. Because i got hold of the context in a normail servlet with
> > this
> > > 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/workflowdb");
> > >
> > > but when I try the same inside a web service I get this
> > >
> > > javax.naming.NameNotFoundException: Name java:comp is not bound in this
> > > Context
> > >
> > > So i guess it's something about classloading etc, but the usual
> solution
> > > about same jar files in <TOMCTA_HOME>/lib and weppAPP/WEB-INF/lib can't
> > be
> > > used here since there are noe similar jar files.
> > >
> > > My enironment is a tomcat 6 and axis2 1.3.
> > >
> > > cheers, Håkon
> > >
> > > 2008/11/5 Mani <mb...@yahoo.com>
> > >
> > >
> > >> Hi
> > >> I am not sure whether you are still facing the issue.
> > >> if yes i think you can try like this:
> > >>
> > >> <properties>
> > >> <property name="openjpa.ConnectionFactoryName"
> > >> value="jdbc/AMPPARTS"
> > >> />
> > >> <property name="openjpa.Log"
> > >> value="DefaultLevel=INFO,Tool=INFO" />
> > >> <property name="openjpa.Sequence"
> > >> value="table(Table=OPENJPA_SEQUENCE_TABLE, Increment=1)"/>
> > >> <property name="openjpa.jdbc.Schema"
> value="Administrator"/>
> > >> </properties>
> > >>
> > >> It worked for me. Try again. All the best.
> > >> -Mani
> > >>
> > >>
> > >> Håkon Sagehaug wrote:
> > >> >
> > >> > Hi
> > >> >
> > >> > I think you may have to send me all ;). I tried from the beginning
> > with
> > >> a
> > >> > clean tomcat and axis 2 install, and configured like you said, but
> > still
> > >> > the
> > >> > same problem, so if you could send me what you think I need for
> > getting
> > >> it
> > >> > to work I would appreciate it
> > >> >
> > >> > cheers, Håkon
> > >> >
> > >> > 2008/11/3 Jeremy Bauer <te...@gmail.com>
> > >> >
> > >> >> Are you running a packaged service within the Axis2 app (an .aar
> > >> archive)
> > >> >> or
> > >> >> is your service deployed as part of a separate web application? I
> > was
> > >> >> able
> > >> >> to get an OpenJPA-based Axis2 service to work deployed within a
> > >> >> standalone
> > >> >> web application. I used Tomcat 5.5, Axis 2-1.4.1 and OpenJPA
> 1.2.0.
> > >> >> I simply added this entry to my <tomcat_home>/conf/context.xml:
> > >> >>
> > >> >> <Resource name="jdbc/TestDB" auth="Container"
> > >> >> type="javax.sql.DataSource"
> > >> >> maxActive="20" maxIdle="10" maxWait="10000"
> > >> >> username="yourusername" password="yourpassword"
> > >> >> driverClassName="com.mysql.jdbc.Driver"
> > >> >>
> > >> >> url="jdbc:mysql://localhost:3306/testdb?autoReconnect=true"/>
> > >> >>
> > >> >> And referenced the data source in my persistence.xml:
> > >> >>
> > >> >> <persistence-unit name="Tomcat">
> > >> >> <jta-data-source>java:comp/env/jdbc/TestDB</jta-data-source>
> > >> >> <class>entities.TestData</class>
> > >> >> </persistence-unit>
> > >> >>
> > >> >> I also added the OpenJPA jar and necessary supporting jars
> > >> >> to <tomcat_home>/common/lib.
> > >> >>
> > >> >> If you'd like a copy of my .war with source please let me know.
> The
> > >> .war
> > >> >> contains Axis2 binaries, which are quite large, so I won't post it
> to
> > >> the
> > >> >> forum. I'd guess using a .aar should work as well (if you happen
> to
> > be
> > >> >> doing that), but the configuration may be different.
> > >> >>
> > >> >> -Jeremy
> > >> >>
> > >> >> On Mon, Nov 3, 2008 at 12:20 PM, Jeremy Bauer <techhusky@gmail.com
> >
> > >> >> wrote:
> > >> >>
> > >> >> > I found this:
> > >> >> >
> > >> >>
> > >>
> >
> http://www.experts-exchange.com/Software/Server_Software/Application_Servers/Java/Apache_Tomcat/Q_23207819.htmlwhich
> > >> >> > indicated that you need to create a resource link between the
> data
> > >> >> source
> > >> >> > you defined in the service.xml and resource ref in the web.xml,
> by
> > >> >> defining
> > >> >> > this in the context.xml:
> > >> >> >
> > >> >> > <ResourceLink global="jdbc/workflowdb" name="jdbc/workflowdb"
> > >> >> > auth="Container"
> > >> >> > type="javax.sql.DataSource"/>
> > >> >> >
> > >> >> > -Jeremy
> > >> >> >
> > >> >> >
> > >> >> > On Mon, Nov 3, 2008 at 11:37 AM, Håkon Sagehaug <
> > >> >> > Hakon.Sagehaug@bccs.uib.no> wrote:
> > >> >> > > Hi
> > >> >> > >
> > >> >> > > when I try to do this programmatically like this
> > >> >> > >
> > >> >> > > Context initCtx = null;
> > >> >> > > Context envCtx;
> > >> >> > > DataSource ds = null;
> > >> >> > > try {
> > >> >> > > initCtx = new InitialContext();
> > >> >> > > // envCtx = (Context) initCtx.lookup("java:/comp/env");
> > >> >> > > ds = (DataSource)
> > >> >> initCtx.lookup("java:comp/env/jdbc/workflowdb");
> > >> >> > > } catch (NamingException e) {
> > >> >> > > // TODO Auto-generated catch block
> > >> >> > > e.printStackTrace();
> > >> >> > > }
> > >> >> > >
> > >> >> > > propMap.put("openjpa.ConnectionFactory", ds);
> > >> >> > > propMap.put("openjpa.ConnectionFactoryMode", "managed");
> > >> >> > > propMap.put("openjpa.FlushBeforeQueries", "false");
> > >> >> > >
> > >> >> > > EntityManagerFactory emf =
> > >> Persistence.createEntityManagerFactory(
> > >> >> > > "MyOpenJPa", propMap);
> > >> >> > >
> > >> >> > > I always get
> > >> >> > >
> > >> >> > > javax.naming.NameNotFoundException: Name java:comp is not bound
> > in
> > >> >> this
> > >> >> > > Context
> > >> >> > >
> > >> >> > > So I guess this is related, but followed the tomcat doc so I
> > can't
> > >> >> > > understand why this does not work.
> > >> >> > > 2008/11/3 Håkon Sagehaug <Ha...@bccs.uib.no>
> > >> >> > >
> > >> >> > >> Hi
> > >> >> > >>
> > >> >> > >> I added resource configuration to the web.xml of axis2, and
> > tried
> > >> >> also
> > >> >> > to
> > >> >> > >> make a web.xml for the web service but neither of this worked.
> > Any
> > >> >> > onther
> > >> >> > >> tips, it world be realy nice to get this to work for me
> > >> >> > >>
> > >> >> > >> cheers, Håkon
> > >> >> > >>
> > >> >> > >> 2008/11/3 Jeremy Bauer <te...@gmail.com>
> > >> >> > >>
> > >> >> > >> You may also need to define a resource reference in your
> > web.xml.
> > >> >> > >>> This link contains a good example on how to configure and use
> a
> > >> >> data
> > >> >> > >>> source:
> > >> >> > >>>
> > >> >> >
> > >> >>
> > >>
> >
> http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
> > >> >> > >>> .
> > >> >> > >>> The configuration part is what is important for OpenJPA,
> since
> > >> it
> > >> >> > >>> just looks up the data source via the JNDI name provided in
> the
> > >> >> > >>> <jta-data-source> element (as Mike pointed out).
> > >> >> > >>>
> > >> >> > >>> -Jeremy
> > >> >> > >>>
> > >> >> > >>> On Mon, Nov 3, 2008 at 9:22 AM, Michael Dick <
> > >> >> michael.d.dick@gmail.com
> > >> >> > >
> > >> >> > >>> wrote:
> > >> >> > >>> > Have you tried
> > >> >> > >>> >
> > >> <jta-data-source>java:comp/env/jdbc/workflowdb</jta-data-source>
> > >> >> > instead
> > >> >> > >>> of
> > >> >> > >>> > the property for openjpa.ConnectionFactoryName?
> > >> >> > >>> >
> > >> >> > >>> > -mike
> > >> >> > >>> >
> > >> >> > >>> > On Mon, Nov 3, 2008 at 8:22 AM, Håkon Sagehaug
> > >> >> > >>> > <Ha...@bccs.uib.no>wrote:
> > >> >> > >>> >
> > >> >> > >>> >> Hi all,
> > >> >> > >>> >>
> > >> >> > >>> >> I've got a axis2 web service that is deployed in tomcat
> and
> > >> talk
> > >> >> to
> > >> >> > a
> > >> >> > >>> >> database using openjpa. This works fine when I just use
> the
> > >> >> > persistent
> > >> >> > >>> xml
> > >> >> > >>> >> to configure my db connection, but now I want to use
> tomcat
> > to
> > >> >> > >>> configure
> > >> >> > >>> >> the
> > >> >> > >>> >> datasource. Here is my set-up
> > >> >> > >>> >>
> > >> >> > >>> >> persistent.xml
> > >> >> > >>> >>
> > >> >> > >>> >>
> > >> >> > >>> >> <persistence-unit name="MyOpenJPa"
> > >> >> > transaction-type="RESOURCE_LOCAL">
> > >> >> > >>> >>
> > >> >> > >>> >>
> > >> >> > >>>
> > >> >> >
> > >> >>
> > >>
> >
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
> > >> >> > >>> >>
> > >> >> > >>> >> <class>demo.hibernate.MyPerson</class>
> > >> >> > >>> >> <properties>
> > >> >> > >>> >> <property name="openjpa.ConnectionFactoryName"
> > >> >> > >>> >> value="java:comp/env/jdbc/workflowdb" />
> > >> >> > >>> >> <property name="openjpa.Log"
> > >> >> value="DefaultLevel=INFO,
> > >> >> > >>> >> Tool=INFO" />
> > >> >> > >>> >> <property name="openjpa.Sequence"
> > >> >> > >>> >> value="table(Table=OPENJPA_SEQUENCE_TABLE, Increment=1)"/>
> > >> >> > >>> >>
> > >> >> > >>> >> </properties>
> > >> >> > >>> >> </persistence-unit>
> > >> >> > >>> >>
> > >> >> > >>> >> In tomcat's service xml I've got this
> > >> >> > >>> >>
> > >> >> > >>> >> <Resource name="jdbc/workflowdb" auth="Container"
> > >> >> > >>> >> type="javax.sql.DataSource"
> > >> >> > >>> >> maxActive="5" maxIdle="5" maxWait="10000"
> > >> >> > >>> >> username="name" password="password"
> > >> >> > >>> >> driverClassName="org.postgresql.Driver"
> > >> >> > >>> >>
> url="jdbc:postgresql://hostname/Workflows"/>
> > >> >> > >>> >>
> > >> >> > >>> >> I tried to put it into the <GlobalNamingResources> tag
> and
> > >> >> inside
> > >> >> a
> > >> >> > >>> >> <Context> tag using the axis2 as path, but I always get
> this
> > >> >> error
> > >> >> > back
> > >> >> > >>> >>
> > >> >> > >>> >> A JDBC Driver or DataSource class name must be specified
> in
> > >> the
> > >> >> > >>> >> ConnectionDriverName property.
> > >> >> > >>> >>
> > >> >> > >>> >> Does anyone have a good tip on how to get this to work??
> > >> >> > >>> >>
> > >> >> > >>> >> cheers, Håkon
> > >> >> > >>> >>
> > >> >> > >>> >> --
> > >> >> > >>> >> Håkon Sagehaug, Software Developer
> > >> >> > >>> >> Parallab, Bergen Center for Computational Science (BCCS)
> > >> >> > >>> >> UNIFOB AS (University of Bergen Research Company)
> > >> >> > >>> >>
> > >> >> > >>> >
> > >> >> > >>>
> > >> >> > >>
> > >> >> > >>
> > >> >> > >>
> > >> >> > >> --
> > >> >> > >> Håkon Sagehaug, Software Developer
> > >> >> > >> Parallab, Bergen Center for Computational Science (BCCS)
> > >> >> > >> UNIFOB AS (University of Bergen Research Company)
> > >> >> > >>
> > >> >> > >
> > >> >> > >
> > >> >> > >
> > >> >> > > --
> > >> >> > > Håkon Sagehaug, Software Developer
> > >> >> > > Parallab, Bergen Center for Computational Science (BCCS)
> > >> >> > > UNIFOB AS (University of Bergen Research Company)
> > >> >> > >
> > >> >> >
> > >> >> >
> > >> >>
> > >> >
> > >> >
> > >> >
> > >> > --
> > >> > Håkon Sagehaug, Software Developer
> > >> > Parallab, Bergen Center for Computational Science (BCCS)
> > >> > UNIFOB AS (University of Bergen Research Company)
> > >> >
> > >> >
> > >>
> > >> --
> > >> View this message in context:
> > >>
> >
> http://n2.nabble.com/Using-datasource-from-tomcat-with-openjpa-tp1449575p1459221.html
> > >> Sent from the OpenJPA Users mailing list archive at Nabble.com.
> > >>
> > >>
> > >
> > >
> > > --
> > > Håkon Sagehaug, Software Developer
> > > Parallab, Bergen Center for Computational Science (BCCS)
> > > UNIFOB AS (University of Bergen Research Company)
> > >
> >
> >
> >
> > --
> > Håkon Sagehaug, Software Developer
> > Parallab, Bergen Center for Computational Science (BCCS)
> > UNIFOB AS (University of Bergen Research Company)
> >
>
--
Håkon Sagehaug, Software Developer
Parallab, Bergen Center for Computational Science (BCCS)
UNIFOB AS (University of Bergen Research Company)
Re: Using datasource from tomcat with openjpa
Posted by Jeremy Bauer <te...@gmail.com>.
Hi Håkon,
Try defining a non-jta data source in your persistence.xml. That should
correct the problem. You can even use the same data source as you've
defined for your jta-data-source name.
ex: <non-jta-data-source>java:comp/env/jdbc/workflowdb</non-jta-data-source>
-Jeremy
On Wed, Nov 5, 2008 at 7:08 AM, Håkon Sagehaug
<Ha...@bccs.uib.no>wrote:
> Hi
>
> I tried to get it to just work on a servlet and have more success here, but
> have now this problem, when I want to get the transaction in my servlet
> like
> this I
>
> em.getTransaction().begin();
>
> and error is thrown
>
> Caused by: java.sql.SQLException: Unable to obtain a TransactionManager
> using null.
> at
>
> org.apache.openjpa.jdbc.kernel.TableJDBCSeq.allocateSequence(TableJDBCSeq.java:419)
> at
>
> org.apache.openjpa.jdbc.kernel.TableJDBCSeq.nextInternal(TableJDBCSeq.java:290)
> at
>
> org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq.next(AbstractJDBCSeq.java:60)
> ... 33 more
> Caused by: javax.transaction.NotSupportedException: Unable to obtain a
> TransactionManager using null.
> at
>
> org.apache.openjpa.ee.AutomaticManagedRuntime.doNonTransactionalWork(AutomaticManagedRuntime.java:306)
> at
>
> org.apache.openjpa.jdbc.kernel.TableJDBCSeq.allocateSequence(TableJDBCSeq.java:415)
> ... 35 more
> Caused by: <openjpa-1.2.0-r422266:683325 fatal user error>
> org.apache.openjpa.util.InvalidStateException: Could not perform automatic
> lookup of EJB container's javax.transaction.TransactionManager
> implementation. Please ensure that you are running the application from
> within an EJB 1.1 compliant EJB container, and then set the
> org.apache.openjpa.ManagedRuntime property to
> at
>
> org.apache.openjpa.ee.AutomaticManagedRuntime.getTransactionManager(AutomaticManagedRuntime.java:250)
> at
>
> org.apache.openjpa.ee.AutomaticManagedRuntime.doNonTransactionalWork(AutomaticManagedRuntime.java:304)
> ... 36 more
> Caused by: javax.naming.NameNotFoundException: Name
> TransactionSynchronizationRegistry is not bound in this Context
> at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
> at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
> at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
> at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
> at org.apache.naming.SelectorContext.lookup(SelectorContext.java:137)
> at javax.naming.InitialContext.lookup(InitialContext.java:392)
> at
>
> org.apache.openjpa.ee.RegistryManagedRuntime.getTransactionManager(RegistryManagedRuntime.java:61)
> at
>
> org.apache.openjpa.ee.AutomaticManagedRuntime.getTransactionManager(AutomaticManagedRuntime.java:168)
> ... 37 more
>
>
> It works fine when I just want to do a db lookup and not involve the
> transaction manager. Do I need to specify a transaction manager in tomcat
> as
> I did with the datasource?
>
> cheers, håkon
>
>
> 2008/11/5 Håkon Sagehaug <Ha...@bccs.uib.no>
>
> > Hi all,
> >
> > I don't know exactly my problems lies, but think it may be in axis or I'm
> > not sure. Because i got hold of the context in a normail servlet with
> this
> > 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/workflowdb");
> >
> > but when I try the same inside a web service I get this
> >
> > javax.naming.NameNotFoundException: Name java:comp is not bound in this
> > Context
> >
> > So i guess it's something about classloading etc, but the usual solution
> > about same jar files in <TOMCTA_HOME>/lib and weppAPP/WEB-INF/lib can't
> be
> > used here since there are noe similar jar files.
> >
> > My enironment is a tomcat 6 and axis2 1.3.
> >
> > cheers, Håkon
> >
> > 2008/11/5 Mani <mb...@yahoo.com>
> >
> >
> >> Hi
> >> I am not sure whether you are still facing the issue.
> >> if yes i think you can try like this:
> >>
> >> <properties>
> >> <property name="openjpa.ConnectionFactoryName"
> >> value="jdbc/AMPPARTS"
> >> />
> >> <property name="openjpa.Log"
> >> value="DefaultLevel=INFO,Tool=INFO" />
> >> <property name="openjpa.Sequence"
> >> value="table(Table=OPENJPA_SEQUENCE_TABLE, Increment=1)"/>
> >> <property name="openjpa.jdbc.Schema" value="Administrator"/>
> >> </properties>
> >>
> >> It worked for me. Try again. All the best.
> >> -Mani
> >>
> >>
> >> Håkon Sagehaug wrote:
> >> >
> >> > Hi
> >> >
> >> > I think you may have to send me all ;). I tried from the beginning
> with
> >> a
> >> > clean tomcat and axis 2 install, and configured like you said, but
> still
> >> > the
> >> > same problem, so if you could send me what you think I need for
> getting
> >> it
> >> > to work I would appreciate it
> >> >
> >> > cheers, Håkon
> >> >
> >> > 2008/11/3 Jeremy Bauer <te...@gmail.com>
> >> >
> >> >> Are you running a packaged service within the Axis2 app (an .aar
> >> archive)
> >> >> or
> >> >> is your service deployed as part of a separate web application? I
> was
> >> >> able
> >> >> to get an OpenJPA-based Axis2 service to work deployed within a
> >> >> standalone
> >> >> web application. I used Tomcat 5.5, Axis 2-1.4.1 and OpenJPA 1.2.0.
> >> >> I simply added this entry to my <tomcat_home>/conf/context.xml:
> >> >>
> >> >> <Resource name="jdbc/TestDB" auth="Container"
> >> >> type="javax.sql.DataSource"
> >> >> maxActive="20" maxIdle="10" maxWait="10000"
> >> >> username="yourusername" password="yourpassword"
> >> >> driverClassName="com.mysql.jdbc.Driver"
> >> >>
> >> >> url="jdbc:mysql://localhost:3306/testdb?autoReconnect=true"/>
> >> >>
> >> >> And referenced the data source in my persistence.xml:
> >> >>
> >> >> <persistence-unit name="Tomcat">
> >> >> <jta-data-source>java:comp/env/jdbc/TestDB</jta-data-source>
> >> >> <class>entities.TestData</class>
> >> >> </persistence-unit>
> >> >>
> >> >> I also added the OpenJPA jar and necessary supporting jars
> >> >> to <tomcat_home>/common/lib.
> >> >>
> >> >> If you'd like a copy of my .war with source please let me know. The
> >> .war
> >> >> contains Axis2 binaries, which are quite large, so I won't post it to
> >> the
> >> >> forum. I'd guess using a .aar should work as well (if you happen to
> be
> >> >> doing that), but the configuration may be different.
> >> >>
> >> >> -Jeremy
> >> >>
> >> >> On Mon, Nov 3, 2008 at 12:20 PM, Jeremy Bauer <te...@gmail.com>
> >> >> wrote:
> >> >>
> >> >> > I found this:
> >> >> >
> >> >>
> >>
> http://www.experts-exchange.com/Software/Server_Software/Application_Servers/Java/Apache_Tomcat/Q_23207819.htmlwhich
> >> >> > indicated that you need to create a resource link between the data
> >> >> source
> >> >> > you defined in the service.xml and resource ref in the web.xml, by
> >> >> defining
> >> >> > this in the context.xml:
> >> >> >
> >> >> > <ResourceLink global="jdbc/workflowdb" name="jdbc/workflowdb"
> >> >> > auth="Container"
> >> >> > type="javax.sql.DataSource"/>
> >> >> >
> >> >> > -Jeremy
> >> >> >
> >> >> >
> >> >> > On Mon, Nov 3, 2008 at 11:37 AM, Håkon Sagehaug <
> >> >> > Hakon.Sagehaug@bccs.uib.no> wrote:
> >> >> > > Hi
> >> >> > >
> >> >> > > when I try to do this programmatically like this
> >> >> > >
> >> >> > > Context initCtx = null;
> >> >> > > Context envCtx;
> >> >> > > DataSource ds = null;
> >> >> > > try {
> >> >> > > initCtx = new InitialContext();
> >> >> > > // envCtx = (Context) initCtx.lookup("java:/comp/env");
> >> >> > > ds = (DataSource)
> >> >> initCtx.lookup("java:comp/env/jdbc/workflowdb");
> >> >> > > } catch (NamingException e) {
> >> >> > > // TODO Auto-generated catch block
> >> >> > > e.printStackTrace();
> >> >> > > }
> >> >> > >
> >> >> > > propMap.put("openjpa.ConnectionFactory", ds);
> >> >> > > propMap.put("openjpa.ConnectionFactoryMode", "managed");
> >> >> > > propMap.put("openjpa.FlushBeforeQueries", "false");
> >> >> > >
> >> >> > > EntityManagerFactory emf =
> >> Persistence.createEntityManagerFactory(
> >> >> > > "MyOpenJPa", propMap);
> >> >> > >
> >> >> > > I always get
> >> >> > >
> >> >> > > javax.naming.NameNotFoundException: Name java:comp is not bound
> in
> >> >> this
> >> >> > > Context
> >> >> > >
> >> >> > > So I guess this is related, but followed the tomcat doc so I
> can't
> >> >> > > understand why this does not work.
> >> >> > > 2008/11/3 Håkon Sagehaug <Ha...@bccs.uib.no>
> >> >> > >
> >> >> > >> Hi
> >> >> > >>
> >> >> > >> I added resource configuration to the web.xml of axis2, and
> tried
> >> >> also
> >> >> > to
> >> >> > >> make a web.xml for the web service but neither of this worked.
> Any
> >> >> > onther
> >> >> > >> tips, it world be realy nice to get this to work for me
> >> >> > >>
> >> >> > >> cheers, Håkon
> >> >> > >>
> >> >> > >> 2008/11/3 Jeremy Bauer <te...@gmail.com>
> >> >> > >>
> >> >> > >> You may also need to define a resource reference in your
> web.xml.
> >> >> > >>> This link contains a good example on how to configure and use a
> >> >> data
> >> >> > >>> source:
> >> >> > >>>
> >> >> >
> >> >>
> >>
> http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
> >> >> > >>> .
> >> >> > >>> The configuration part is what is important for OpenJPA, since
> >> it
> >> >> > >>> just looks up the data source via the JNDI name provided in the
> >> >> > >>> <jta-data-source> element (as Mike pointed out).
> >> >> > >>>
> >> >> > >>> -Jeremy
> >> >> > >>>
> >> >> > >>> On Mon, Nov 3, 2008 at 9:22 AM, Michael Dick <
> >> >> michael.d.dick@gmail.com
> >> >> > >
> >> >> > >>> wrote:
> >> >> > >>> > Have you tried
> >> >> > >>> >
> >> <jta-data-source>java:comp/env/jdbc/workflowdb</jta-data-source>
> >> >> > instead
> >> >> > >>> of
> >> >> > >>> > the property for openjpa.ConnectionFactoryName?
> >> >> > >>> >
> >> >> > >>> > -mike
> >> >> > >>> >
> >> >> > >>> > On Mon, Nov 3, 2008 at 8:22 AM, Håkon Sagehaug
> >> >> > >>> > <Ha...@bccs.uib.no>wrote:
> >> >> > >>> >
> >> >> > >>> >> Hi all,
> >> >> > >>> >>
> >> >> > >>> >> I've got a axis2 web service that is deployed in tomcat and
> >> talk
> >> >> to
> >> >> > a
> >> >> > >>> >> database using openjpa. This works fine when I just use the
> >> >> > persistent
> >> >> > >>> xml
> >> >> > >>> >> to configure my db connection, but now I want to use tomcat
> to
> >> >> > >>> configure
> >> >> > >>> >> the
> >> >> > >>> >> datasource. Here is my set-up
> >> >> > >>> >>
> >> >> > >>> >> persistent.xml
> >> >> > >>> >>
> >> >> > >>> >>
> >> >> > >>> >> <persistence-unit name="MyOpenJPa"
> >> >> > transaction-type="RESOURCE_LOCAL">
> >> >> > >>> >>
> >> >> > >>> >>
> >> >> > >>>
> >> >> >
> >> >>
> >>
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
> >> >> > >>> >>
> >> >> > >>> >> <class>demo.hibernate.MyPerson</class>
> >> >> > >>> >> <properties>
> >> >> > >>> >> <property name="openjpa.ConnectionFactoryName"
> >> >> > >>> >> value="java:comp/env/jdbc/workflowdb" />
> >> >> > >>> >> <property name="openjpa.Log"
> >> >> value="DefaultLevel=INFO,
> >> >> > >>> >> Tool=INFO" />
> >> >> > >>> >> <property name="openjpa.Sequence"
> >> >> > >>> >> value="table(Table=OPENJPA_SEQUENCE_TABLE, Increment=1)"/>
> >> >> > >>> >>
> >> >> > >>> >> </properties>
> >> >> > >>> >> </persistence-unit>
> >> >> > >>> >>
> >> >> > >>> >> In tomcat's service xml I've got this
> >> >> > >>> >>
> >> >> > >>> >> <Resource name="jdbc/workflowdb" auth="Container"
> >> >> > >>> >> type="javax.sql.DataSource"
> >> >> > >>> >> maxActive="5" maxIdle="5" maxWait="10000"
> >> >> > >>> >> username="name" password="password"
> >> >> > >>> >> driverClassName="org.postgresql.Driver"
> >> >> > >>> >> url="jdbc:postgresql://hostname/Workflows"/>
> >> >> > >>> >>
> >> >> > >>> >> I tried to put it into the <GlobalNamingResources> tag and
> >> >> inside
> >> >> a
> >> >> > >>> >> <Context> tag using the axis2 as path, but I always get this
> >> >> error
> >> >> > back
> >> >> > >>> >>
> >> >> > >>> >> A JDBC Driver or DataSource class name must be specified in
> >> the
> >> >> > >>> >> ConnectionDriverName property.
> >> >> > >>> >>
> >> >> > >>> >> Does anyone have a good tip on how to get this to work??
> >> >> > >>> >>
> >> >> > >>> >> cheers, Håkon
> >> >> > >>> >>
> >> >> > >>> >> --
> >> >> > >>> >> Håkon Sagehaug, Software Developer
> >> >> > >>> >> Parallab, Bergen Center for Computational Science (BCCS)
> >> >> > >>> >> UNIFOB AS (University of Bergen Research Company)
> >> >> > >>> >>
> >> >> > >>> >
> >> >> > >>>
> >> >> > >>
> >> >> > >>
> >> >> > >>
> >> >> > >> --
> >> >> > >> Håkon Sagehaug, Software Developer
> >> >> > >> Parallab, Bergen Center for Computational Science (BCCS)
> >> >> > >> UNIFOB AS (University of Bergen Research Company)
> >> >> > >>
> >> >> > >
> >> >> > >
> >> >> > >
> >> >> > > --
> >> >> > > Håkon Sagehaug, Software Developer
> >> >> > > Parallab, Bergen Center for Computational Science (BCCS)
> >> >> > > UNIFOB AS (University of Bergen Research Company)
> >> >> > >
> >> >> >
> >> >> >
> >> >>
> >> >
> >> >
> >> >
> >> > --
> >> > Håkon Sagehaug, Software Developer
> >> > Parallab, Bergen Center for Computational Science (BCCS)
> >> > UNIFOB AS (University of Bergen Research Company)
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >>
> http://n2.nabble.com/Using-datasource-from-tomcat-with-openjpa-tp1449575p1459221.html
> >> Sent from the OpenJPA Users mailing list archive at Nabble.com.
> >>
> >>
> >
> >
> > --
> > Håkon Sagehaug, Software Developer
> > Parallab, Bergen Center for Computational Science (BCCS)
> > UNIFOB AS (University of Bergen Research Company)
> >
>
>
>
> --
> Håkon Sagehaug, Software Developer
> Parallab, Bergen Center for Computational Science (BCCS)
> UNIFOB AS (University of Bergen Research Company)
>
Re: Using datasource from tomcat with openjpa
Posted by Håkon Sagehaug <Ha...@bccs.uib.no>.
Hi
I tried to get it to just work on a servlet and have more success here, but
have now this problem, when I want to get the transaction in my servlet like
this I
em.getTransaction().begin();
and error is thrown
Caused by: java.sql.SQLException: Unable to obtain a TransactionManager
using null.
at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq.allocateSequence(TableJDBCSeq.java:419)
at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq.nextInternal(TableJDBCSeq.java:290)
at
org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq.next(AbstractJDBCSeq.java:60)
... 33 more
Caused by: javax.transaction.NotSupportedException: Unable to obtain a
TransactionManager using null.
at
org.apache.openjpa.ee.AutomaticManagedRuntime.doNonTransactionalWork(AutomaticManagedRuntime.java:306)
at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq.allocateSequence(TableJDBCSeq.java:415)
... 35 more
Caused by: <openjpa-1.2.0-r422266:683325 fatal user error>
org.apache.openjpa.util.InvalidStateException: Could not perform automatic
lookup of EJB container's javax.transaction.TransactionManager
implementation. Please ensure that you are running the application from
within an EJB 1.1 compliant EJB container, and then set the
org.apache.openjpa.ManagedRuntime property to
at
org.apache.openjpa.ee.AutomaticManagedRuntime.getTransactionManager(AutomaticManagedRuntime.java:250)
at
org.apache.openjpa.ee.AutomaticManagedRuntime.doNonTransactionalWork(AutomaticManagedRuntime.java:304)
... 36 more
Caused by: javax.naming.NameNotFoundException: Name
TransactionSynchronizationRegistry is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:137)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at
org.apache.openjpa.ee.RegistryManagedRuntime.getTransactionManager(RegistryManagedRuntime.java:61)
at
org.apache.openjpa.ee.AutomaticManagedRuntime.getTransactionManager(AutomaticManagedRuntime.java:168)
... 37 more
It works fine when I just want to do a db lookup and not involve the
transaction manager. Do I need to specify a transaction manager in tomcat as
I did with the datasource?
cheers, håkon
2008/11/5 Håkon Sagehaug <Ha...@bccs.uib.no>
> Hi all,
>
> I don't know exactly my problems lies, but think it may be in axis or I'm
> not sure. Because i got hold of the context in a normail servlet with this
> 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/workflowdb");
>
> but when I try the same inside a web service I get this
>
> javax.naming.NameNotFoundException: Name java:comp is not bound in this
> Context
>
> So i guess it's something about classloading etc, but the usual solution
> about same jar files in <TOMCTA_HOME>/lib and weppAPP/WEB-INF/lib can't be
> used here since there are noe similar jar files.
>
> My enironment is a tomcat 6 and axis2 1.3.
>
> cheers, Håkon
>
> 2008/11/5 Mani <mb...@yahoo.com>
>
>
>> Hi
>> I am not sure whether you are still facing the issue.
>> if yes i think you can try like this:
>>
>> <properties>
>> <property name="openjpa.ConnectionFactoryName"
>> value="jdbc/AMPPARTS"
>> />
>> <property name="openjpa.Log"
>> value="DefaultLevel=INFO,Tool=INFO" />
>> <property name="openjpa.Sequence"
>> value="table(Table=OPENJPA_SEQUENCE_TABLE, Increment=1)"/>
>> <property name="openjpa.jdbc.Schema" value="Administrator"/>
>> </properties>
>>
>> It worked for me. Try again. All the best.
>> -Mani
>>
>>
>> Håkon Sagehaug wrote:
>> >
>> > Hi
>> >
>> > I think you may have to send me all ;). I tried from the beginning with
>> a
>> > clean tomcat and axis 2 install, and configured like you said, but still
>> > the
>> > same problem, so if you could send me what you think I need for getting
>> it
>> > to work I would appreciate it
>> >
>> > cheers, Håkon
>> >
>> > 2008/11/3 Jeremy Bauer <te...@gmail.com>
>> >
>> >> Are you running a packaged service within the Axis2 app (an .aar
>> archive)
>> >> or
>> >> is your service deployed as part of a separate web application? I was
>> >> able
>> >> to get an OpenJPA-based Axis2 service to work deployed within a
>> >> standalone
>> >> web application. I used Tomcat 5.5, Axis 2-1.4.1 and OpenJPA 1.2.0.
>> >> I simply added this entry to my <tomcat_home>/conf/context.xml:
>> >>
>> >> <Resource name="jdbc/TestDB" auth="Container"
>> >> type="javax.sql.DataSource"
>> >> maxActive="20" maxIdle="10" maxWait="10000"
>> >> username="yourusername" password="yourpassword"
>> >> driverClassName="com.mysql.jdbc.Driver"
>> >>
>> >> url="jdbc:mysql://localhost:3306/testdb?autoReconnect=true"/>
>> >>
>> >> And referenced the data source in my persistence.xml:
>> >>
>> >> <persistence-unit name="Tomcat">
>> >> <jta-data-source>java:comp/env/jdbc/TestDB</jta-data-source>
>> >> <class>entities.TestData</class>
>> >> </persistence-unit>
>> >>
>> >> I also added the OpenJPA jar and necessary supporting jars
>> >> to <tomcat_home>/common/lib.
>> >>
>> >> If you'd like a copy of my .war with source please let me know. The
>> .war
>> >> contains Axis2 binaries, which are quite large, so I won't post it to
>> the
>> >> forum. I'd guess using a .aar should work as well (if you happen to be
>> >> doing that), but the configuration may be different.
>> >>
>> >> -Jeremy
>> >>
>> >> On Mon, Nov 3, 2008 at 12:20 PM, Jeremy Bauer <te...@gmail.com>
>> >> wrote:
>> >>
>> >> > I found this:
>> >> >
>> >>
>> http://www.experts-exchange.com/Software/Server_Software/Application_Servers/Java/Apache_Tomcat/Q_23207819.htmlwhich
>> >> > indicated that you need to create a resource link between the data
>> >> source
>> >> > you defined in the service.xml and resource ref in the web.xml, by
>> >> defining
>> >> > this in the context.xml:
>> >> >
>> >> > <ResourceLink global="jdbc/workflowdb" name="jdbc/workflowdb"
>> >> > auth="Container"
>> >> > type="javax.sql.DataSource"/>
>> >> >
>> >> > -Jeremy
>> >> >
>> >> >
>> >> > On Mon, Nov 3, 2008 at 11:37 AM, Håkon Sagehaug <
>> >> > Hakon.Sagehaug@bccs.uib.no> wrote:
>> >> > > Hi
>> >> > >
>> >> > > when I try to do this programmatically like this
>> >> > >
>> >> > > Context initCtx = null;
>> >> > > Context envCtx;
>> >> > > DataSource ds = null;
>> >> > > try {
>> >> > > initCtx = new InitialContext();
>> >> > > // envCtx = (Context) initCtx.lookup("java:/comp/env");
>> >> > > ds = (DataSource)
>> >> initCtx.lookup("java:comp/env/jdbc/workflowdb");
>> >> > > } catch (NamingException e) {
>> >> > > // TODO Auto-generated catch block
>> >> > > e.printStackTrace();
>> >> > > }
>> >> > >
>> >> > > propMap.put("openjpa.ConnectionFactory", ds);
>> >> > > propMap.put("openjpa.ConnectionFactoryMode", "managed");
>> >> > > propMap.put("openjpa.FlushBeforeQueries", "false");
>> >> > >
>> >> > > EntityManagerFactory emf =
>> Persistence.createEntityManagerFactory(
>> >> > > "MyOpenJPa", propMap);
>> >> > >
>> >> > > I always get
>> >> > >
>> >> > > javax.naming.NameNotFoundException: Name java:comp is not bound in
>> >> this
>> >> > > Context
>> >> > >
>> >> > > So I guess this is related, but followed the tomcat doc so I can't
>> >> > > understand why this does not work.
>> >> > > 2008/11/3 Håkon Sagehaug <Ha...@bccs.uib.no>
>> >> > >
>> >> > >> Hi
>> >> > >>
>> >> > >> I added resource configuration to the web.xml of axis2, and tried
>> >> also
>> >> > to
>> >> > >> make a web.xml for the web service but neither of this worked. Any
>> >> > onther
>> >> > >> tips, it world be realy nice to get this to work for me
>> >> > >>
>> >> > >> cheers, Håkon
>> >> > >>
>> >> > >> 2008/11/3 Jeremy Bauer <te...@gmail.com>
>> >> > >>
>> >> > >> You may also need to define a resource reference in your web.xml.
>> >> > >>> This link contains a good example on how to configure and use a
>> >> data
>> >> > >>> source:
>> >> > >>>
>> >> >
>> >>
>> http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
>> >> > >>> .
>> >> > >>> The configuration part is what is important for OpenJPA, since
>> it
>> >> > >>> just looks up the data source via the JNDI name provided in the
>> >> > >>> <jta-data-source> element (as Mike pointed out).
>> >> > >>>
>> >> > >>> -Jeremy
>> >> > >>>
>> >> > >>> On Mon, Nov 3, 2008 at 9:22 AM, Michael Dick <
>> >> michael.d.dick@gmail.com
>> >> > >
>> >> > >>> wrote:
>> >> > >>> > Have you tried
>> >> > >>> >
>> <jta-data-source>java:comp/env/jdbc/workflowdb</jta-data-source>
>> >> > instead
>> >> > >>> of
>> >> > >>> > the property for openjpa.ConnectionFactoryName?
>> >> > >>> >
>> >> > >>> > -mike
>> >> > >>> >
>> >> > >>> > On Mon, Nov 3, 2008 at 8:22 AM, Håkon Sagehaug
>> >> > >>> > <Ha...@bccs.uib.no>wrote:
>> >> > >>> >
>> >> > >>> >> Hi all,
>> >> > >>> >>
>> >> > >>> >> I've got a axis2 web service that is deployed in tomcat and
>> talk
>> >> to
>> >> > a
>> >> > >>> >> database using openjpa. This works fine when I just use the
>> >> > persistent
>> >> > >>> xml
>> >> > >>> >> to configure my db connection, but now I want to use tomcat to
>> >> > >>> configure
>> >> > >>> >> the
>> >> > >>> >> datasource. Here is my set-up
>> >> > >>> >>
>> >> > >>> >> persistent.xml
>> >> > >>> >>
>> >> > >>> >>
>> >> > >>> >> <persistence-unit name="MyOpenJPa"
>> >> > transaction-type="RESOURCE_LOCAL">
>> >> > >>> >>
>> >> > >>> >>
>> >> > >>>
>> >> >
>> >>
>> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>> >> > >>> >>
>> >> > >>> >> <class>demo.hibernate.MyPerson</class>
>> >> > >>> >> <properties>
>> >> > >>> >> <property name="openjpa.ConnectionFactoryName"
>> >> > >>> >> value="java:comp/env/jdbc/workflowdb" />
>> >> > >>> >> <property name="openjpa.Log"
>> >> value="DefaultLevel=INFO,
>> >> > >>> >> Tool=INFO" />
>> >> > >>> >> <property name="openjpa.Sequence"
>> >> > >>> >> value="table(Table=OPENJPA_SEQUENCE_TABLE, Increment=1)"/>
>> >> > >>> >>
>> >> > >>> >> </properties>
>> >> > >>> >> </persistence-unit>
>> >> > >>> >>
>> >> > >>> >> In tomcat's service xml I've got this
>> >> > >>> >>
>> >> > >>> >> <Resource name="jdbc/workflowdb" auth="Container"
>> >> > >>> >> type="javax.sql.DataSource"
>> >> > >>> >> maxActive="5" maxIdle="5" maxWait="10000"
>> >> > >>> >> username="name" password="password"
>> >> > >>> >> driverClassName="org.postgresql.Driver"
>> >> > >>> >> url="jdbc:postgresql://hostname/Workflows"/>
>> >> > >>> >>
>> >> > >>> >> I tried to put it into the <GlobalNamingResources> tag and
>> >> inside
>> >> a
>> >> > >>> >> <Context> tag using the axis2 as path, but I always get this
>> >> error
>> >> > back
>> >> > >>> >>
>> >> > >>> >> A JDBC Driver or DataSource class name must be specified in
>> the
>> >> > >>> >> ConnectionDriverName property.
>> >> > >>> >>
>> >> > >>> >> Does anyone have a good tip on how to get this to work??
>> >> > >>> >>
>> >> > >>> >> cheers, Håkon
>> >> > >>> >>
>> >> > >>> >> --
>> >> > >>> >> Håkon Sagehaug, Software Developer
>> >> > >>> >> Parallab, Bergen Center for Computational Science (BCCS)
>> >> > >>> >> UNIFOB AS (University of Bergen Research Company)
>> >> > >>> >>
>> >> > >>> >
>> >> > >>>
>> >> > >>
>> >> > >>
>> >> > >>
>> >> > >> --
>> >> > >> Håkon Sagehaug, Software Developer
>> >> > >> Parallab, Bergen Center for Computational Science (BCCS)
>> >> > >> UNIFOB AS (University of Bergen Research Company)
>> >> > >>
>> >> > >
>> >> > >
>> >> > >
>> >> > > --
>> >> > > Håkon Sagehaug, Software Developer
>> >> > > Parallab, Bergen Center for Computational Science (BCCS)
>> >> > > UNIFOB AS (University of Bergen Research Company)
>> >> > >
>> >> >
>> >> >
>> >>
>> >
>> >
>> >
>> > --
>> > Håkon Sagehaug, Software Developer
>> > Parallab, Bergen Center for Computational Science (BCCS)
>> > UNIFOB AS (University of Bergen Research Company)
>> >
>> >
>>
>> --
>> View this message in context:
>> http://n2.nabble.com/Using-datasource-from-tomcat-with-openjpa-tp1449575p1459221.html
>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>
>>
>
>
> --
> Håkon Sagehaug, Software Developer
> Parallab, Bergen Center for Computational Science (BCCS)
> UNIFOB AS (University of Bergen Research Company)
>
--
Håkon Sagehaug, Software Developer
Parallab, Bergen Center for Computational Science (BCCS)
UNIFOB AS (University of Bergen Research Company)
Re: Using datasource from tomcat with openjpa
Posted by Håkon Sagehaug <Ha...@bccs.uib.no>.
Hi all,
I don't know exactly my problems lies, but think it may be in axis or I'm
not sure. Because i got hold of the context in a normail servlet with this
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/workflowdb");
but when I try the same inside a web service I get this
javax.naming.NameNotFoundException: Name java:comp is not bound in this
Context
So i guess it's something about classloading etc, but the usual solution
about same jar files in <TOMCTA_HOME>/lib and weppAPP/WEB-INF/lib can't be
used here since there are noe similar jar files.
My enironment is a tomcat 6 and axis2 1.3.
cheers, Håkon
2008/11/5 Mani <mb...@yahoo.com>
>
> Hi
> I am not sure whether you are still facing the issue.
> if yes i think you can try like this:
>
> <properties>
> <property name="openjpa.ConnectionFactoryName"
> value="jdbc/AMPPARTS"
> />
> <property name="openjpa.Log"
> value="DefaultLevel=INFO,Tool=INFO" />
> <property name="openjpa.Sequence"
> value="table(Table=OPENJPA_SEQUENCE_TABLE, Increment=1)"/>
> <property name="openjpa.jdbc.Schema" value="Administrator"/>
> </properties>
>
> It worked for me. Try again. All the best.
> -Mani
>
>
> Håkon Sagehaug wrote:
> >
> > Hi
> >
> > I think you may have to send me all ;). I tried from the beginning with a
> > clean tomcat and axis 2 install, and configured like you said, but still
> > the
> > same problem, so if you could send me what you think I need for getting
> it
> > to work I would appreciate it
> >
> > cheers, Håkon
> >
> > 2008/11/3 Jeremy Bauer <te...@gmail.com>
> >
> >> Are you running a packaged service within the Axis2 app (an .aar
> archive)
> >> or
> >> is your service deployed as part of a separate web application? I was
> >> able
> >> to get an OpenJPA-based Axis2 service to work deployed within a
> >> standalone
> >> web application. I used Tomcat 5.5, Axis 2-1.4.1 and OpenJPA 1.2.0.
> >> I simply added this entry to my <tomcat_home>/conf/context.xml:
> >>
> >> <Resource name="jdbc/TestDB" auth="Container"
> >> type="javax.sql.DataSource"
> >> maxActive="20" maxIdle="10" maxWait="10000"
> >> username="yourusername" password="yourpassword"
> >> driverClassName="com.mysql.jdbc.Driver"
> >>
> >> url="jdbc:mysql://localhost:3306/testdb?autoReconnect=true"/>
> >>
> >> And referenced the data source in my persistence.xml:
> >>
> >> <persistence-unit name="Tomcat">
> >> <jta-data-source>java:comp/env/jdbc/TestDB</jta-data-source>
> >> <class>entities.TestData</class>
> >> </persistence-unit>
> >>
> >> I also added the OpenJPA jar and necessary supporting jars
> >> to <tomcat_home>/common/lib.
> >>
> >> If you'd like a copy of my .war with source please let me know. The
> .war
> >> contains Axis2 binaries, which are quite large, so I won't post it to
> the
> >> forum. I'd guess using a .aar should work as well (if you happen to be
> >> doing that), but the configuration may be different.
> >>
> >> -Jeremy
> >>
> >> On Mon, Nov 3, 2008 at 12:20 PM, Jeremy Bauer <te...@gmail.com>
> >> wrote:
> >>
> >> > I found this:
> >> >
> >>
> http://www.experts-exchange.com/Software/Server_Software/Application_Servers/Java/Apache_Tomcat/Q_23207819.htmlwhich
> >> > indicated that you need to create a resource link between the data
> >> source
> >> > you defined in the service.xml and resource ref in the web.xml, by
> >> defining
> >> > this in the context.xml:
> >> >
> >> > <ResourceLink global="jdbc/workflowdb" name="jdbc/workflowdb"
> >> > auth="Container"
> >> > type="javax.sql.DataSource"/>
> >> >
> >> > -Jeremy
> >> >
> >> >
> >> > On Mon, Nov 3, 2008 at 11:37 AM, Håkon Sagehaug <
> >> > Hakon.Sagehaug@bccs.uib.no> wrote:
> >> > > Hi
> >> > >
> >> > > when I try to do this programmatically like this
> >> > >
> >> > > Context initCtx = null;
> >> > > Context envCtx;
> >> > > DataSource ds = null;
> >> > > try {
> >> > > initCtx = new InitialContext();
> >> > > // envCtx = (Context) initCtx.lookup("java:/comp/env");
> >> > > ds = (DataSource)
> >> initCtx.lookup("java:comp/env/jdbc/workflowdb");
> >> > > } catch (NamingException e) {
> >> > > // TODO Auto-generated catch block
> >> > > e.printStackTrace();
> >> > > }
> >> > >
> >> > > propMap.put("openjpa.ConnectionFactory", ds);
> >> > > propMap.put("openjpa.ConnectionFactoryMode", "managed");
> >> > > propMap.put("openjpa.FlushBeforeQueries", "false");
> >> > >
> >> > > EntityManagerFactory emf =
> Persistence.createEntityManagerFactory(
> >> > > "MyOpenJPa", propMap);
> >> > >
> >> > > I always get
> >> > >
> >> > > javax.naming.NameNotFoundException: Name java:comp is not bound in
> >> this
> >> > > Context
> >> > >
> >> > > So I guess this is related, but followed the tomcat doc so I can't
> >> > > understand why this does not work.
> >> > > 2008/11/3 Håkon Sagehaug <Ha...@bccs.uib.no>
> >> > >
> >> > >> Hi
> >> > >>
> >> > >> I added resource configuration to the web.xml of axis2, and tried
> >> also
> >> > to
> >> > >> make a web.xml for the web service but neither of this worked. Any
> >> > onther
> >> > >> tips, it world be realy nice to get this to work for me
> >> > >>
> >> > >> cheers, Håkon
> >> > >>
> >> > >> 2008/11/3 Jeremy Bauer <te...@gmail.com>
> >> > >>
> >> > >> You may also need to define a resource reference in your web.xml.
> >> > >>> This link contains a good example on how to configure and use a
> >> data
> >> > >>> source:
> >> > >>>
> >> >
> >>
> http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
> >> > >>> .
> >> > >>> The configuration part is what is important for OpenJPA, since it
> >> > >>> just looks up the data source via the JNDI name provided in the
> >> > >>> <jta-data-source> element (as Mike pointed out).
> >> > >>>
> >> > >>> -Jeremy
> >> > >>>
> >> > >>> On Mon, Nov 3, 2008 at 9:22 AM, Michael Dick <
> >> michael.d.dick@gmail.com
> >> > >
> >> > >>> wrote:
> >> > >>> > Have you tried
> >> > >>> > <jta-data-source>java:comp/env/jdbc/workflowdb</jta-data-source>
> >> > instead
> >> > >>> of
> >> > >>> > the property for openjpa.ConnectionFactoryName?
> >> > >>> >
> >> > >>> > -mike
> >> > >>> >
> >> > >>> > On Mon, Nov 3, 2008 at 8:22 AM, Håkon Sagehaug
> >> > >>> > <Ha...@bccs.uib.no>wrote:
> >> > >>> >
> >> > >>> >> Hi all,
> >> > >>> >>
> >> > >>> >> I've got a axis2 web service that is deployed in tomcat and
> talk
> >> to
> >> > a
> >> > >>> >> database using openjpa. This works fine when I just use the
> >> > persistent
> >> > >>> xml
> >> > >>> >> to configure my db connection, but now I want to use tomcat to
> >> > >>> configure
> >> > >>> >> the
> >> > >>> >> datasource. Here is my set-up
> >> > >>> >>
> >> > >>> >> persistent.xml
> >> > >>> >>
> >> > >>> >>
> >> > >>> >> <persistence-unit name="MyOpenJPa"
> >> > transaction-type="RESOURCE_LOCAL">
> >> > >>> >>
> >> > >>> >>
> >> > >>>
> >> >
> >>
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
> >> > >>> >>
> >> > >>> >> <class>demo.hibernate.MyPerson</class>
> >> > >>> >> <properties>
> >> > >>> >> <property name="openjpa.ConnectionFactoryName"
> >> > >>> >> value="java:comp/env/jdbc/workflowdb" />
> >> > >>> >> <property name="openjpa.Log"
> >> value="DefaultLevel=INFO,
> >> > >>> >> Tool=INFO" />
> >> > >>> >> <property name="openjpa.Sequence"
> >> > >>> >> value="table(Table=OPENJPA_SEQUENCE_TABLE, Increment=1)"/>
> >> > >>> >>
> >> > >>> >> </properties>
> >> > >>> >> </persistence-unit>
> >> > >>> >>
> >> > >>> >> In tomcat's service xml I've got this
> >> > >>> >>
> >> > >>> >> <Resource name="jdbc/workflowdb" auth="Container"
> >> > >>> >> type="javax.sql.DataSource"
> >> > >>> >> maxActive="5" maxIdle="5" maxWait="10000"
> >> > >>> >> username="name" password="password"
> >> > >>> >> driverClassName="org.postgresql.Driver"
> >> > >>> >> url="jdbc:postgresql://hostname/Workflows"/>
> >> > >>> >>
> >> > >>> >> I tried to put it into the <GlobalNamingResources> tag and
> >> inside
> >> a
> >> > >>> >> <Context> tag using the axis2 as path, but I always get this
> >> error
> >> > back
> >> > >>> >>
> >> > >>> >> A JDBC Driver or DataSource class name must be specified in the
> >> > >>> >> ConnectionDriverName property.
> >> > >>> >>
> >> > >>> >> Does anyone have a good tip on how to get this to work??
> >> > >>> >>
> >> > >>> >> cheers, Håkon
> >> > >>> >>
> >> > >>> >> --
> >> > >>> >> Håkon Sagehaug, Software Developer
> >> > >>> >> Parallab, Bergen Center for Computational Science (BCCS)
> >> > >>> >> UNIFOB AS (University of Bergen Research Company)
> >> > >>> >>
> >> > >>> >
> >> > >>>
> >> > >>
> >> > >>
> >> > >>
> >> > >> --
> >> > >> Håkon Sagehaug, Software Developer
> >> > >> Parallab, Bergen Center for Computational Science (BCCS)
> >> > >> UNIFOB AS (University of Bergen Research Company)
> >> > >>
> >> > >
> >> > >
> >> > >
> >> > > --
> >> > > Håkon Sagehaug, Software Developer
> >> > > Parallab, Bergen Center for Computational Science (BCCS)
> >> > > UNIFOB AS (University of Bergen Research Company)
> >> > >
> >> >
> >> >
> >>
> >
> >
> >
> > --
> > Håkon Sagehaug, Software Developer
> > Parallab, Bergen Center for Computational Science (BCCS)
> > UNIFOB AS (University of Bergen Research Company)
> >
> >
>
> --
> View this message in context:
> http://n2.nabble.com/Using-datasource-from-tomcat-with-openjpa-tp1449575p1459221.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
>
--
Håkon Sagehaug, Software Developer
Parallab, Bergen Center for Computational Science (BCCS)
UNIFOB AS (University of Bergen Research Company)
Re: Using datasource from tomcat with openjpa
Posted by Mani <mb...@yahoo.com>.
Hi
I am not sure whether you are still facing the issue.
if yes i think you can try like this:
<properties>
<property name="openjpa.ConnectionFactoryName" value="jdbc/AMPPARTS"
/>
<property name="openjpa.Log"
value="DefaultLevel=INFO,Tool=INFO" />
<property name="openjpa.Sequence"
value="table(Table=OPENJPA_SEQUENCE_TABLE, Increment=1)"/>
<property name="openjpa.jdbc.Schema" value="Administrator"/>
</properties>
It worked for me. Try again. All the best.
-Mani
Håkon Sagehaug wrote:
>
> Hi
>
> I think you may have to send me all ;). I tried from the beginning with a
> clean tomcat and axis 2 install, and configured like you said, but still
> the
> same problem, so if you could send me what you think I need for getting it
> to work I would appreciate it
>
> cheers, Håkon
>
> 2008/11/3 Jeremy Bauer <te...@gmail.com>
>
>> Are you running a packaged service within the Axis2 app (an .aar archive)
>> or
>> is your service deployed as part of a separate web application? I was
>> able
>> to get an OpenJPA-based Axis2 service to work deployed within a
>> standalone
>> web application. I used Tomcat 5.5, Axis 2-1.4.1 and OpenJPA 1.2.0.
>> I simply added this entry to my <tomcat_home>/conf/context.xml:
>>
>> <Resource name="jdbc/TestDB" auth="Container"
>> type="javax.sql.DataSource"
>> maxActive="20" maxIdle="10" maxWait="10000"
>> username="yourusername" password="yourpassword"
>> driverClassName="com.mysql.jdbc.Driver"
>>
>> url="jdbc:mysql://localhost:3306/testdb?autoReconnect=true"/>
>>
>> And referenced the data source in my persistence.xml:
>>
>> <persistence-unit name="Tomcat">
>> <jta-data-source>java:comp/env/jdbc/TestDB</jta-data-source>
>> <class>entities.TestData</class>
>> </persistence-unit>
>>
>> I also added the OpenJPA jar and necessary supporting jars
>> to <tomcat_home>/common/lib.
>>
>> If you'd like a copy of my .war with source please let me know. The .war
>> contains Axis2 binaries, which are quite large, so I won't post it to the
>> forum. I'd guess using a .aar should work as well (if you happen to be
>> doing that), but the configuration may be different.
>>
>> -Jeremy
>>
>> On Mon, Nov 3, 2008 at 12:20 PM, Jeremy Bauer <te...@gmail.com>
>> wrote:
>>
>> > I found this:
>> >
>> http://www.experts-exchange.com/Software/Server_Software/Application_Servers/Java/Apache_Tomcat/Q_23207819.htmlwhich
>> > indicated that you need to create a resource link between the data
>> source
>> > you defined in the service.xml and resource ref in the web.xml, by
>> defining
>> > this in the context.xml:
>> >
>> > <ResourceLink global="jdbc/workflowdb" name="jdbc/workflowdb"
>> > auth="Container"
>> > type="javax.sql.DataSource"/>
>> >
>> > -Jeremy
>> >
>> >
>> > On Mon, Nov 3, 2008 at 11:37 AM, Håkon Sagehaug <
>> > Hakon.Sagehaug@bccs.uib.no> wrote:
>> > > Hi
>> > >
>> > > when I try to do this programmatically like this
>> > >
>> > > Context initCtx = null;
>> > > Context envCtx;
>> > > DataSource ds = null;
>> > > try {
>> > > initCtx = new InitialContext();
>> > > // envCtx = (Context) initCtx.lookup("java:/comp/env");
>> > > ds = (DataSource)
>> initCtx.lookup("java:comp/env/jdbc/workflowdb");
>> > > } catch (NamingException e) {
>> > > // TODO Auto-generated catch block
>> > > e.printStackTrace();
>> > > }
>> > >
>> > > propMap.put("openjpa.ConnectionFactory", ds);
>> > > propMap.put("openjpa.ConnectionFactoryMode", "managed");
>> > > propMap.put("openjpa.FlushBeforeQueries", "false");
>> > >
>> > > EntityManagerFactory emf = Persistence.createEntityManagerFactory(
>> > > "MyOpenJPa", propMap);
>> > >
>> > > I always get
>> > >
>> > > javax.naming.NameNotFoundException: Name java:comp is not bound in
>> this
>> > > Context
>> > >
>> > > So I guess this is related, but followed the tomcat doc so I can't
>> > > understand why this does not work.
>> > > 2008/11/3 Håkon Sagehaug <Ha...@bccs.uib.no>
>> > >
>> > >> Hi
>> > >>
>> > >> I added resource configuration to the web.xml of axis2, and tried
>> also
>> > to
>> > >> make a web.xml for the web service but neither of this worked. Any
>> > onther
>> > >> tips, it world be realy nice to get this to work for me
>> > >>
>> > >> cheers, Håkon
>> > >>
>> > >> 2008/11/3 Jeremy Bauer <te...@gmail.com>
>> > >>
>> > >> You may also need to define a resource reference in your web.xml.
>> > >>> This link contains a good example on how to configure and use a
>> data
>> > >>> source:
>> > >>>
>> >
>> http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
>> > >>> .
>> > >>> The configuration part is what is important for OpenJPA, since it
>> > >>> just looks up the data source via the JNDI name provided in the
>> > >>> <jta-data-source> element (as Mike pointed out).
>> > >>>
>> > >>> -Jeremy
>> > >>>
>> > >>> On Mon, Nov 3, 2008 at 9:22 AM, Michael Dick <
>> michael.d.dick@gmail.com
>> > >
>> > >>> wrote:
>> > >>> > Have you tried
>> > >>> > <jta-data-source>java:comp/env/jdbc/workflowdb</jta-data-source>
>> > instead
>> > >>> of
>> > >>> > the property for openjpa.ConnectionFactoryName?
>> > >>> >
>> > >>> > -mike
>> > >>> >
>> > >>> > On Mon, Nov 3, 2008 at 8:22 AM, Håkon Sagehaug
>> > >>> > <Ha...@bccs.uib.no>wrote:
>> > >>> >
>> > >>> >> Hi all,
>> > >>> >>
>> > >>> >> I've got a axis2 web service that is deployed in tomcat and talk
>> to
>> > a
>> > >>> >> database using openjpa. This works fine when I just use the
>> > persistent
>> > >>> xml
>> > >>> >> to configure my db connection, but now I want to use tomcat to
>> > >>> configure
>> > >>> >> the
>> > >>> >> datasource. Here is my set-up
>> > >>> >>
>> > >>> >> persistent.xml
>> > >>> >>
>> > >>> >>
>> > >>> >> <persistence-unit name="MyOpenJPa"
>> > transaction-type="RESOURCE_LOCAL">
>> > >>> >>
>> > >>> >>
>> > >>>
>> >
>> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>> > >>> >>
>> > >>> >> <class>demo.hibernate.MyPerson</class>
>> > >>> >> <properties>
>> > >>> >> <property name="openjpa.ConnectionFactoryName"
>> > >>> >> value="java:comp/env/jdbc/workflowdb" />
>> > >>> >> <property name="openjpa.Log"
>> value="DefaultLevel=INFO,
>> > >>> >> Tool=INFO" />
>> > >>> >> <property name="openjpa.Sequence"
>> > >>> >> value="table(Table=OPENJPA_SEQUENCE_TABLE, Increment=1)"/>
>> > >>> >>
>> > >>> >> </properties>
>> > >>> >> </persistence-unit>
>> > >>> >>
>> > >>> >> In tomcat's service xml I've got this
>> > >>> >>
>> > >>> >> <Resource name="jdbc/workflowdb" auth="Container"
>> > >>> >> type="javax.sql.DataSource"
>> > >>> >> maxActive="5" maxIdle="5" maxWait="10000"
>> > >>> >> username="name" password="password"
>> > >>> >> driverClassName="org.postgresql.Driver"
>> > >>> >> url="jdbc:postgresql://hostname/Workflows"/>
>> > >>> >>
>> > >>> >> I tried to put it into the <GlobalNamingResources> tag and
>> inside
>> a
>> > >>> >> <Context> tag using the axis2 as path, but I always get this
>> error
>> > back
>> > >>> >>
>> > >>> >> A JDBC Driver or DataSource class name must be specified in the
>> > >>> >> ConnectionDriverName property.
>> > >>> >>
>> > >>> >> Does anyone have a good tip on how to get this to work??
>> > >>> >>
>> > >>> >> cheers, Håkon
>> > >>> >>
>> > >>> >> --
>> > >>> >> Håkon Sagehaug, Software Developer
>> > >>> >> Parallab, Bergen Center for Computational Science (BCCS)
>> > >>> >> UNIFOB AS (University of Bergen Research Company)
>> > >>> >>
>> > >>> >
>> > >>>
>> > >>
>> > >>
>> > >>
>> > >> --
>> > >> Håkon Sagehaug, Software Developer
>> > >> Parallab, Bergen Center for Computational Science (BCCS)
>> > >> UNIFOB AS (University of Bergen Research Company)
>> > >>
>> > >
>> > >
>> > >
>> > > --
>> > > Håkon Sagehaug, Software Developer
>> > > Parallab, Bergen Center for Computational Science (BCCS)
>> > > UNIFOB AS (University of Bergen Research Company)
>> > >
>> >
>> >
>>
>
>
>
> --
> Håkon Sagehaug, Software Developer
> Parallab, Bergen Center for Computational Science (BCCS)
> UNIFOB AS (University of Bergen Research Company)
>
>
--
View this message in context: http://n2.nabble.com/Using-datasource-from-tomcat-with-openjpa-tp1449575p1459221.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: Using datasource from tomcat with openjpa
Posted by Håkon Sagehaug <Ha...@bccs.uib.no>.
Hi
I think you may have to send me all ;). I tried from the beginning with a
clean tomcat and axis 2 install, and configured like you said, but still the
same problem, so if you could send me what you think I need for getting it
to work I would appreciate it
cheers, Håkon
2008/11/3 Jeremy Bauer <te...@gmail.com>
> Are you running a packaged service within the Axis2 app (an .aar archive)
> or
> is your service deployed as part of a separate web application? I was able
> to get an OpenJPA-based Axis2 service to work deployed within a standalone
> web application. I used Tomcat 5.5, Axis 2-1.4.1 and OpenJPA 1.2.0.
> I simply added this entry to my <tomcat_home>/conf/context.xml:
>
> <Resource name="jdbc/TestDB" auth="Container"
> type="javax.sql.DataSource"
> maxActive="20" maxIdle="10" maxWait="10000"
> username="yourusername" password="yourpassword"
> driverClassName="com.mysql.jdbc.Driver"
> url="jdbc:mysql://localhost:3306/testdb?autoReconnect=true"/>
>
> And referenced the data source in my persistence.xml:
>
> <persistence-unit name="Tomcat">
> <jta-data-source>java:comp/env/jdbc/TestDB</jta-data-source>
> <class>entities.TestData</class>
> </persistence-unit>
>
> I also added the OpenJPA jar and necessary supporting jars
> to <tomcat_home>/common/lib.
>
> If you'd like a copy of my .war with source please let me know. The .war
> contains Axis2 binaries, which are quite large, so I won't post it to the
> forum. I'd guess using a .aar should work as well (if you happen to be
> doing that), but the configuration may be different.
>
> -Jeremy
>
> On Mon, Nov 3, 2008 at 12:20 PM, Jeremy Bauer <te...@gmail.com> wrote:
>
> > I found this:
> >
> http://www.experts-exchange.com/Software/Server_Software/Application_Servers/Java/Apache_Tomcat/Q_23207819.htmlwhich
> > indicated that you need to create a resource link between the data source
> > you defined in the service.xml and resource ref in the web.xml, by
> defining
> > this in the context.xml:
> >
> > <ResourceLink global="jdbc/workflowdb" name="jdbc/workflowdb"
> > auth="Container"
> > type="javax.sql.DataSource"/>
> >
> > -Jeremy
> >
> >
> > On Mon, Nov 3, 2008 at 11:37 AM, Håkon Sagehaug <
> > Hakon.Sagehaug@bccs.uib.no> wrote:
> > > Hi
> > >
> > > when I try to do this programmatically like this
> > >
> > > Context initCtx = null;
> > > Context envCtx;
> > > DataSource ds = null;
> > > try {
> > > initCtx = new InitialContext();
> > > // envCtx = (Context) initCtx.lookup("java:/comp/env");
> > > ds = (DataSource)
> initCtx.lookup("java:comp/env/jdbc/workflowdb");
> > > } catch (NamingException e) {
> > > // TODO Auto-generated catch block
> > > e.printStackTrace();
> > > }
> > >
> > > propMap.put("openjpa.ConnectionFactory", ds);
> > > propMap.put("openjpa.ConnectionFactoryMode", "managed");
> > > propMap.put("openjpa.FlushBeforeQueries", "false");
> > >
> > > EntityManagerFactory emf = Persistence.createEntityManagerFactory(
> > > "MyOpenJPa", propMap);
> > >
> > > I always get
> > >
> > > javax.naming.NameNotFoundException: Name java:comp is not bound in this
> > > Context
> > >
> > > So I guess this is related, but followed the tomcat doc so I can't
> > > understand why this does not work.
> > > 2008/11/3 Håkon Sagehaug <Ha...@bccs.uib.no>
> > >
> > >> Hi
> > >>
> > >> I added resource configuration to the web.xml of axis2, and tried also
> > to
> > >> make a web.xml for the web service but neither of this worked. Any
> > onther
> > >> tips, it world be realy nice to get this to work for me
> > >>
> > >> cheers, Håkon
> > >>
> > >> 2008/11/3 Jeremy Bauer <te...@gmail.com>
> > >>
> > >> You may also need to define a resource reference in your web.xml.
> > >>> This link contains a good example on how to configure and use a data
> > >>> source:
> > >>>
> >
> http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
> > >>> .
> > >>> The configuration part is what is important for OpenJPA, since it
> > >>> just looks up the data source via the JNDI name provided in the
> > >>> <jta-data-source> element (as Mike pointed out).
> > >>>
> > >>> -Jeremy
> > >>>
> > >>> On Mon, Nov 3, 2008 at 9:22 AM, Michael Dick <
> michael.d.dick@gmail.com
> > >
> > >>> wrote:
> > >>> > Have you tried
> > >>> > <jta-data-source>java:comp/env/jdbc/workflowdb</jta-data-source>
> > instead
> > >>> of
> > >>> > the property for openjpa.ConnectionFactoryName?
> > >>> >
> > >>> > -mike
> > >>> >
> > >>> > On Mon, Nov 3, 2008 at 8:22 AM, Håkon Sagehaug
> > >>> > <Ha...@bccs.uib.no>wrote:
> > >>> >
> > >>> >> Hi all,
> > >>> >>
> > >>> >> I've got a axis2 web service that is deployed in tomcat and talk
> to
> > a
> > >>> >> database using openjpa. This works fine when I just use the
> > persistent
> > >>> xml
> > >>> >> to configure my db connection, but now I want to use tomcat to
> > >>> configure
> > >>> >> the
> > >>> >> datasource. Here is my set-up
> > >>> >>
> > >>> >> persistent.xml
> > >>> >>
> > >>> >>
> > >>> >> <persistence-unit name="MyOpenJPa"
> > transaction-type="RESOURCE_LOCAL">
> > >>> >>
> > >>> >>
> > >>>
> >
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
> > >>> >>
> > >>> >> <class>demo.hibernate.MyPerson</class>
> > >>> >> <properties>
> > >>> >> <property name="openjpa.ConnectionFactoryName"
> > >>> >> value="java:comp/env/jdbc/workflowdb" />
> > >>> >> <property name="openjpa.Log" value="DefaultLevel=INFO,
> > >>> >> Tool=INFO" />
> > >>> >> <property name="openjpa.Sequence"
> > >>> >> value="table(Table=OPENJPA_SEQUENCE_TABLE, Increment=1)"/>
> > >>> >>
> > >>> >> </properties>
> > >>> >> </persistence-unit>
> > >>> >>
> > >>> >> In tomcat's service xml I've got this
> > >>> >>
> > >>> >> <Resource name="jdbc/workflowdb" auth="Container"
> > >>> >> type="javax.sql.DataSource"
> > >>> >> maxActive="5" maxIdle="5" maxWait="10000"
> > >>> >> username="name" password="password"
> > >>> >> driverClassName="org.postgresql.Driver"
> > >>> >> url="jdbc:postgresql://hostname/Workflows"/>
> > >>> >>
> > >>> >> I tried to put it into the <GlobalNamingResources> tag and inside
> a
> > >>> >> <Context> tag using the axis2 as path, but I always get this error
> > back
> > >>> >>
> > >>> >> A JDBC Driver or DataSource class name must be specified in the
> > >>> >> ConnectionDriverName property.
> > >>> >>
> > >>> >> Does anyone have a good tip on how to get this to work??
> > >>> >>
> > >>> >> cheers, Håkon
> > >>> >>
> > >>> >> --
> > >>> >> Håkon Sagehaug, Software Developer
> > >>> >> Parallab, Bergen Center for Computational Science (BCCS)
> > >>> >> UNIFOB AS (University of Bergen Research Company)
> > >>> >>
> > >>> >
> > >>>
> > >>
> > >>
> > >>
> > >> --
> > >> Håkon Sagehaug, Software Developer
> > >> Parallab, Bergen Center for Computational Science (BCCS)
> > >> UNIFOB AS (University of Bergen Research Company)
> > >>
> > >
> > >
> > >
> > > --
> > > Håkon Sagehaug, Software Developer
> > > Parallab, Bergen Center for Computational Science (BCCS)
> > > UNIFOB AS (University of Bergen Research Company)
> > >
> >
> >
>
--
Håkon Sagehaug, Software Developer
Parallab, Bergen Center for Computational Science (BCCS)
UNIFOB AS (University of Bergen Research Company)
Re: Using datasource from tomcat with openjpa
Posted by Jeremy Bauer <te...@gmail.com>.
Are you running a packaged service within the Axis2 app (an .aar archive) or
is your service deployed as part of a separate web application? I was able
to get an OpenJPA-based Axis2 service to work deployed within a standalone
web application. I used Tomcat 5.5, Axis 2-1.4.1 and OpenJPA 1.2.0.
I simply added this entry to my <tomcat_home>/conf/context.xml:
<Resource name="jdbc/TestDB" auth="Container"
type="javax.sql.DataSource"
maxActive="20" maxIdle="10" maxWait="10000"
username="yourusername" password="yourpassword"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/testdb?autoReconnect=true"/>
And referenced the data source in my persistence.xml:
<persistence-unit name="Tomcat">
<jta-data-source>java:comp/env/jdbc/TestDB</jta-data-source>
<class>entities.TestData</class>
</persistence-unit>
I also added the OpenJPA jar and necessary supporting jars
to <tomcat_home>/common/lib.
If you'd like a copy of my .war with source please let me know. The .war
contains Axis2 binaries, which are quite large, so I won't post it to the
forum. I'd guess using a .aar should work as well (if you happen to be
doing that), but the configuration may be different.
-Jeremy
On Mon, Nov 3, 2008 at 12:20 PM, Jeremy Bauer <te...@gmail.com> wrote:
> I found this:
> http://www.experts-exchange.com/Software/Server_Software/Application_Servers/Java/Apache_Tomcat/Q_23207819.html which
> indicated that you need to create a resource link between the data source
> you defined in the service.xml and resource ref in the web.xml, by defining
> this in the context.xml:
>
> <ResourceLink global="jdbc/workflowdb" name="jdbc/workflowdb"
> auth="Container"
> type="javax.sql.DataSource"/>
>
> -Jeremy
>
>
> On Mon, Nov 3, 2008 at 11:37 AM, Håkon Sagehaug <
> Hakon.Sagehaug@bccs.uib.no> wrote:
> > Hi
> >
> > when I try to do this programmatically like this
> >
> > Context initCtx = null;
> > Context envCtx;
> > DataSource ds = null;
> > try {
> > initCtx = new InitialContext();
> > // envCtx = (Context) initCtx.lookup("java:/comp/env");
> > ds = (DataSource) initCtx.lookup("java:comp/env/jdbc/workflowdb");
> > } catch (NamingException e) {
> > // TODO Auto-generated catch block
> > e.printStackTrace();
> > }
> >
> > propMap.put("openjpa.ConnectionFactory", ds);
> > propMap.put("openjpa.ConnectionFactoryMode", "managed");
> > propMap.put("openjpa.FlushBeforeQueries", "false");
> >
> > EntityManagerFactory emf = Persistence.createEntityManagerFactory(
> > "MyOpenJPa", propMap);
> >
> > I always get
> >
> > javax.naming.NameNotFoundException: Name java:comp is not bound in this
> > Context
> >
> > So I guess this is related, but followed the tomcat doc so I can't
> > understand why this does not work.
> > 2008/11/3 Håkon Sagehaug <Ha...@bccs.uib.no>
> >
> >> Hi
> >>
> >> I added resource configuration to the web.xml of axis2, and tried also
> to
> >> make a web.xml for the web service but neither of this worked. Any
> onther
> >> tips, it world be realy nice to get this to work for me
> >>
> >> cheers, Håkon
> >>
> >> 2008/11/3 Jeremy Bauer <te...@gmail.com>
> >>
> >> You may also need to define a resource reference in your web.xml.
> >>> This link contains a good example on how to configure and use a data
> >>> source:
> >>>
> http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
> >>> .
> >>> The configuration part is what is important for OpenJPA, since it
> >>> just looks up the data source via the JNDI name provided in the
> >>> <jta-data-source> element (as Mike pointed out).
> >>>
> >>> -Jeremy
> >>>
> >>> On Mon, Nov 3, 2008 at 9:22 AM, Michael Dick <michael.d.dick@gmail.com
> >
> >>> wrote:
> >>> > Have you tried
> >>> > <jta-data-source>java:comp/env/jdbc/workflowdb</jta-data-source>
> instead
> >>> of
> >>> > the property for openjpa.ConnectionFactoryName?
> >>> >
> >>> > -mike
> >>> >
> >>> > On Mon, Nov 3, 2008 at 8:22 AM, Håkon Sagehaug
> >>> > <Ha...@bccs.uib.no>wrote:
> >>> >
> >>> >> Hi all,
> >>> >>
> >>> >> I've got a axis2 web service that is deployed in tomcat and talk to
> a
> >>> >> database using openjpa. This works fine when I just use the
> persistent
> >>> xml
> >>> >> to configure my db connection, but now I want to use tomcat to
> >>> configure
> >>> >> the
> >>> >> datasource. Here is my set-up
> >>> >>
> >>> >> persistent.xml
> >>> >>
> >>> >>
> >>> >> <persistence-unit name="MyOpenJPa"
> transaction-type="RESOURCE_LOCAL">
> >>> >>
> >>> >>
> >>>
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
> >>> >>
> >>> >> <class>demo.hibernate.MyPerson</class>
> >>> >> <properties>
> >>> >> <property name="openjpa.ConnectionFactoryName"
> >>> >> value="java:comp/env/jdbc/workflowdb" />
> >>> >> <property name="openjpa.Log" value="DefaultLevel=INFO,
> >>> >> Tool=INFO" />
> >>> >> <property name="openjpa.Sequence"
> >>> >> value="table(Table=OPENJPA_SEQUENCE_TABLE, Increment=1)"/>
> >>> >>
> >>> >> </properties>
> >>> >> </persistence-unit>
> >>> >>
> >>> >> In tomcat's service xml I've got this
> >>> >>
> >>> >> <Resource name="jdbc/workflowdb" auth="Container"
> >>> >> type="javax.sql.DataSource"
> >>> >> maxActive="5" maxIdle="5" maxWait="10000"
> >>> >> username="name" password="password"
> >>> >> driverClassName="org.postgresql.Driver"
> >>> >> url="jdbc:postgresql://hostname/Workflows"/>
> >>> >>
> >>> >> I tried to put it into the <GlobalNamingResources> tag and inside a
> >>> >> <Context> tag using the axis2 as path, but I always get this error
> back
> >>> >>
> >>> >> A JDBC Driver or DataSource class name must be specified in the
> >>> >> ConnectionDriverName property.
> >>> >>
> >>> >> Does anyone have a good tip on how to get this to work??
> >>> >>
> >>> >> cheers, Håkon
> >>> >>
> >>> >> --
> >>> >> Håkon Sagehaug, Software Developer
> >>> >> Parallab, Bergen Center for Computational Science (BCCS)
> >>> >> UNIFOB AS (University of Bergen Research Company)
> >>> >>
> >>> >
> >>>
> >>
> >>
> >>
> >> --
> >> Håkon Sagehaug, Software Developer
> >> Parallab, Bergen Center for Computational Science (BCCS)
> >> UNIFOB AS (University of Bergen Research Company)
> >>
> >
> >
> >
> > --
> > Håkon Sagehaug, Software Developer
> > Parallab, Bergen Center for Computational Science (BCCS)
> > UNIFOB AS (University of Bergen Research Company)
> >
>
>
Re: Using datasource from tomcat with openjpa
Posted by Jeremy Bauer <te...@gmail.com>.
I found this:
http://www.experts-exchange.com/Software/Server_Software/Application_Servers/Java/Apache_Tomcat/Q_23207819.html
which
indicated that you need to create a resource link between the data source
you defined in the service.xml and resource ref in the web.xml, by defining
this in the context.xml:
<ResourceLink global="jdbc/workflowdb" name="jdbc/workflowdb"
auth="Container"
type="javax.sql.DataSource"/>
-Jeremy
On Mon, Nov 3, 2008 at 11:37 AM, Håkon Sagehaug <Ha...@bccs.uib.no>
wrote:
> Hi
>
> when I try to do this programmatically like this
>
> Context initCtx = null;
> Context envCtx;
> DataSource ds = null;
> try {
> initCtx = new InitialContext();
> // envCtx = (Context) initCtx.lookup("java:/comp/env");
> ds = (DataSource) initCtx.lookup("java:comp/env/jdbc/workflowdb");
> } catch (NamingException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
> propMap.put("openjpa.ConnectionFactory", ds);
> propMap.put("openjpa.ConnectionFactoryMode", "managed");
> propMap.put("openjpa.FlushBeforeQueries", "false");
>
> EntityManagerFactory emf = Persistence.createEntityManagerFactory(
> "MyOpenJPa", propMap);
>
> I always get
>
> javax.naming.NameNotFoundException: Name java:comp is not bound in this
> Context
>
> So I guess this is related, but followed the tomcat doc so I can't
> understand why this does not work.
> 2008/11/3 Håkon Sagehaug <Ha...@bccs.uib.no>
>
>> Hi
>>
>> I added resource configuration to the web.xml of axis2, and tried also to
>> make a web.xml for the web service but neither of this worked. Any onther
>> tips, it world be realy nice to get this to work for me
>>
>> cheers, Håkon
>>
>> 2008/11/3 Jeremy Bauer <te...@gmail.com>
>>
>> You may also need to define a resource reference in your web.xml.
>>> This link contains a good example on how to configure and use a data
>>> source:
>>>
http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
>>> .
>>> The configuration part is what is important for OpenJPA, since it
>>> just looks up the data source via the JNDI name provided in the
>>> <jta-data-source> element (as Mike pointed out).
>>>
>>> -Jeremy
>>>
>>> On Mon, Nov 3, 2008 at 9:22 AM, Michael Dick <mi...@gmail.com>
>>> wrote:
>>> > Have you tried
>>> > <jta-data-source>java:comp/env/jdbc/workflowdb</jta-data-source>
instead
>>> of
>>> > the property for openjpa.ConnectionFactoryName?
>>> >
>>> > -mike
>>> >
>>> > On Mon, Nov 3, 2008 at 8:22 AM, Håkon Sagehaug
>>> > <Ha...@bccs.uib.no>wrote:
>>> >
>>> >> Hi all,
>>> >>
>>> >> I've got a axis2 web service that is deployed in tomcat and talk to a
>>> >> database using openjpa. This works fine when I just use the
persistent
>>> xml
>>> >> to configure my db connection, but now I want to use tomcat to
>>> configure
>>> >> the
>>> >> datasource. Here is my set-up
>>> >>
>>> >> persistent.xml
>>> >>
>>> >>
>>> >> <persistence-unit name="MyOpenJPa" transaction-type="RESOURCE_LOCAL">
>>> >>
>>> >>
>>>
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>>> >>
>>> >> <class>demo.hibernate.MyPerson</class>
>>> >> <properties>
>>> >> <property name="openjpa.ConnectionFactoryName"
>>> >> value="java:comp/env/jdbc/workflowdb" />
>>> >> <property name="openjpa.Log" value="DefaultLevel=INFO,
>>> >> Tool=INFO" />
>>> >> <property name="openjpa.Sequence"
>>> >> value="table(Table=OPENJPA_SEQUENCE_TABLE, Increment=1)"/>
>>> >>
>>> >> </properties>
>>> >> </persistence-unit>
>>> >>
>>> >> In tomcat's service xml I've got this
>>> >>
>>> >> <Resource name="jdbc/workflowdb" auth="Container"
>>> >> type="javax.sql.DataSource"
>>> >> maxActive="5" maxIdle="5" maxWait="10000"
>>> >> username="name" password="password"
>>> >> driverClassName="org.postgresql.Driver"
>>> >> url="jdbc:postgresql://hostname/Workflows"/>
>>> >>
>>> >> I tried to put it into the <GlobalNamingResources> tag and inside a
>>> >> <Context> tag using the axis2 as path, but I always get this error
back
>>> >>
>>> >> A JDBC Driver or DataSource class name must be specified in the
>>> >> ConnectionDriverName property.
>>> >>
>>> >> Does anyone have a good tip on how to get this to work??
>>> >>
>>> >> cheers, Håkon
>>> >>
>>> >> --
>>> >> Håkon Sagehaug, Software Developer
>>> >> Parallab, Bergen Center for Computational Science (BCCS)
>>> >> UNIFOB AS (University of Bergen Research Company)
>>> >>
>>> >
>>>
>>
>>
>>
>> --
>> Håkon Sagehaug, Software Developer
>> Parallab, Bergen Center for Computational Science (BCCS)
>> UNIFOB AS (University of Bergen Research Company)
>>
>
>
>
> --
> Håkon Sagehaug, Software Developer
> Parallab, Bergen Center for Computational Science (BCCS)
> UNIFOB AS (University of Bergen Research Company)
>
Re: Using datasource from tomcat with openjpa
Posted by Sandhya Kishore <tu...@yahoo.com>.
Hi
Usually this exception "javax.naming.NameNotFoundException: Name java:comp is not bound in this Context" occurs in Tomcat when you have the same jar files in WEB-INF/lib and Tomcat's Common/lib folder. This is the problem I faced long back when I was using tomcat and got resolved as soon as I removed those conflicting jars from my webapp. you can try the same. Hopefully this will help.
Thanks
Sandhya
--- On Mon, 11/3/08, Håkon Sagehaug <Ha...@bccs.uib.no> wrote:
From: Håkon Sagehaug <Ha...@bccs.uib.no>
Subject: Re: Using datasource from tomcat with openjpa
To: users@openjpa.apache.org
Date: Monday, November 3, 2008, 9:37 AM
Hi
when I try to do this programmatically like this
Context initCtx = null;
Context envCtx;
DataSource ds = null;
try {
initCtx = new InitialContext();
// envCtx = (Context) initCtx.lookup("java:/comp/env");
ds = (DataSource)
initCtx.lookup("java:comp/env/jdbc/workflowdb");
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
propMap.put("openjpa.ConnectionFactory", ds);
propMap.put("openjpa.ConnectionFactoryMode",
"managed");
propMap.put("openjpa.FlushBeforeQueries", "false");
EntityManagerFactory emf = Persistence.createEntityManagerFactory(
"MyOpenJPa", propMap);
I always get
javax.naming.NameNotFoundException: Name java:comp is not bound in this
Context
So I guess this is related, but followed the tomcat doc so I can't
understand why this does not work.
2008/11/3 Håkon Sagehaug <Ha...@bccs.uib.no>
> Hi
>
> I added resource configuration to the web.xml of axis2, and tried also to
> make a web.xml for the web service but neither of this worked. Any onther
> tips, it world be realy nice to get this to work for me
>
> cheers, Håkon
>
> 2008/11/3 Jeremy Bauer <te...@gmail.com>
>
> You may also need to define a resource reference in your web.xml.
>> This link contains a good example on how to configure and use a data
>> source:
>>
http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
>> .
>> The configuration part is what is important for OpenJPA, since it
>> just looks up the data source via the JNDI name provided in the
>> <jta-data-source> element (as Mike pointed out).
>>
>> -Jeremy
>>
>> On Mon, Nov 3, 2008 at 9:22 AM, Michael Dick
<mi...@gmail.com>
>> wrote:
>> > Have you tried
>> >
<jta-data-source>java:comp/env/jdbc/workflowdb</jta-data-source>
instead
>> of
>> > the property for openjpa.ConnectionFactoryName?
>> >
>> > -mike
>> >
>> > On Mon, Nov 3, 2008 at 8:22 AM, Håkon Sagehaug
>> > <Ha...@bccs.uib.no>wrote:
>> >
>> >> Hi all,
>> >>
>> >> I've got a axis2 web service that is deployed in tomcat
and talk to a
>> >> database using openjpa. This works fine when I just use the
persistent
>> xml
>> >> to configure my db connection, but now I want to use tomcat
to
>> configure
>> >> the
>> >> datasource. Here is my set-up
>> >>
>> >> persistent.xml
>> >>
>> >>
>> >> <persistence-unit name="MyOpenJPa"
transaction-type="RESOURCE_LOCAL">
>> >>
>> >>
>>
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>> >>
>> >> <class>demo.hibernate.MyPerson</class>
>> >> <properties>
>> >> <property
name="openjpa.ConnectionFactoryName"
>> >> value="java:comp/env/jdbc/workflowdb" />
>> >> <property name="openjpa.Log"
value="DefaultLevel=INFO,
>> >> Tool=INFO" />
>> >> <property name="openjpa.Sequence"
>> >> value="table(Table=OPENJPA_SEQUENCE_TABLE,
Increment=1)"/>
>> >>
>> >> </properties>
>> >> </persistence-unit>
>> >>
>> >> In tomcat's service xml I've got this
>> >>
>> >> <Resource name="jdbc/workflowdb"
auth="Container"
>> >> type="javax.sql.DataSource"
>> >> maxActive="5" maxIdle="5"
maxWait="10000"
>> >> username="name"
password="password"
>> >> driverClassName="org.postgresql.Driver"
>> >>
url="jdbc:postgresql://hostname/Workflows"/>
>> >>
>> >> I tried to put it into the <GlobalNamingResources> tag
and inside a
>> >> <Context> tag using the axis2 as path, but I always get
this error back
>> >>
>> >> A JDBC Driver or DataSource class name must be specified in
the
>> >> ConnectionDriverName property.
>> >>
>> >> Does anyone have a good tip on how to get this to work??
>> >>
>> >> cheers, Håkon
>> >>
>> >> --
>> >> Håkon Sagehaug, Software Developer
>> >> Parallab, Bergen Center for Computational Science (BCCS)
>> >> UNIFOB AS (University of Bergen Research Company)
>> >>
>> >
>>
>
>
>
> --
> Håkon Sagehaug, Software Developer
> Parallab, Bergen Center for Computational Science (BCCS)
> UNIFOB AS (University of Bergen Research Company)
>
--
Håkon Sagehaug, Software Developer
Parallab, Bergen Center for Computational Science (BCCS)
UNIFOB AS (University of Bergen Research Company)
Re: Using datasource from tomcat with openjpa
Posted by Håkon Sagehaug <Ha...@bccs.uib.no>.
Hi
when I try to do this programmatically like this
Context initCtx = null;
Context envCtx;
DataSource ds = null;
try {
initCtx = new InitialContext();
// envCtx = (Context) initCtx.lookup("java:/comp/env");
ds = (DataSource) initCtx.lookup("java:comp/env/jdbc/workflowdb");
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
propMap.put("openjpa.ConnectionFactory", ds);
propMap.put("openjpa.ConnectionFactoryMode", "managed");
propMap.put("openjpa.FlushBeforeQueries", "false");
EntityManagerFactory emf = Persistence.createEntityManagerFactory(
"MyOpenJPa", propMap);
I always get
javax.naming.NameNotFoundException: Name java:comp is not bound in this
Context
So I guess this is related, but followed the tomcat doc so I can't
understand why this does not work.
2008/11/3 Håkon Sagehaug <Ha...@bccs.uib.no>
> Hi
>
> I added resource configuration to the web.xml of axis2, and tried also to
> make a web.xml for the web service but neither of this worked. Any onther
> tips, it world be realy nice to get this to work for me
>
> cheers, Håkon
>
> 2008/11/3 Jeremy Bauer <te...@gmail.com>
>
> You may also need to define a resource reference in your web.xml.
>> This link contains a good example on how to configure and use a data
>> source:
>> http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
>> .
>> The configuration part is what is important for OpenJPA, since it
>> just looks up the data source via the JNDI name provided in the
>> <jta-data-source> element (as Mike pointed out).
>>
>> -Jeremy
>>
>> On Mon, Nov 3, 2008 at 9:22 AM, Michael Dick <mi...@gmail.com>
>> wrote:
>> > Have you tried
>> > <jta-data-source>java:comp/env/jdbc/workflowdb</jta-data-source> instead
>> of
>> > the property for openjpa.ConnectionFactoryName?
>> >
>> > -mike
>> >
>> > On Mon, Nov 3, 2008 at 8:22 AM, Håkon Sagehaug
>> > <Ha...@bccs.uib.no>wrote:
>> >
>> >> Hi all,
>> >>
>> >> I've got a axis2 web service that is deployed in tomcat and talk to a
>> >> database using openjpa. This works fine when I just use the persistent
>> xml
>> >> to configure my db connection, but now I want to use tomcat to
>> configure
>> >> the
>> >> datasource. Here is my set-up
>> >>
>> >> persistent.xml
>> >>
>> >>
>> >> <persistence-unit name="MyOpenJPa" transaction-type="RESOURCE_LOCAL">
>> >>
>> >>
>> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>> >>
>> >> <class>demo.hibernate.MyPerson</class>
>> >> <properties>
>> >> <property name="openjpa.ConnectionFactoryName"
>> >> value="java:comp/env/jdbc/workflowdb" />
>> >> <property name="openjpa.Log" value="DefaultLevel=INFO,
>> >> Tool=INFO" />
>> >> <property name="openjpa.Sequence"
>> >> value="table(Table=OPENJPA_SEQUENCE_TABLE, Increment=1)"/>
>> >>
>> >> </properties>
>> >> </persistence-unit>
>> >>
>> >> In tomcat's service xml I've got this
>> >>
>> >> <Resource name="jdbc/workflowdb" auth="Container"
>> >> type="javax.sql.DataSource"
>> >> maxActive="5" maxIdle="5" maxWait="10000"
>> >> username="name" password="password"
>> >> driverClassName="org.postgresql.Driver"
>> >> url="jdbc:postgresql://hostname/Workflows"/>
>> >>
>> >> I tried to put it into the <GlobalNamingResources> tag and inside a
>> >> <Context> tag using the axis2 as path, but I always get this error back
>> >>
>> >> A JDBC Driver or DataSource class name must be specified in the
>> >> ConnectionDriverName property.
>> >>
>> >> Does anyone have a good tip on how to get this to work??
>> >>
>> >> cheers, Håkon
>> >>
>> >> --
>> >> Håkon Sagehaug, Software Developer
>> >> Parallab, Bergen Center for Computational Science (BCCS)
>> >> UNIFOB AS (University of Bergen Research Company)
>> >>
>> >
>>
>
>
>
> --
> Håkon Sagehaug, Software Developer
> Parallab, Bergen Center for Computational Science (BCCS)
> UNIFOB AS (University of Bergen Research Company)
>
--
Håkon Sagehaug, Software Developer
Parallab, Bergen Center for Computational Science (BCCS)
UNIFOB AS (University of Bergen Research Company)
Re: Using datasource from tomcat with openjpa
Posted by Håkon Sagehaug <Ha...@bccs.uib.no>.
Hi
I added resource configuration to the web.xml of axis2, and tried also to
make a web.xml for the web service but neither of this worked. Any onther
tips, it world be realy nice to get this to work for me
cheers, Håkon
2008/11/3 Jeremy Bauer <te...@gmail.com>
> You may also need to define a resource reference in your web.xml.
> This link contains a good example on how to configure and use a data
> source:
> http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
> .
> The configuration part is what is important for OpenJPA, since it
> just looks up the data source via the JNDI name provided in the
> <jta-data-source> element (as Mike pointed out).
>
> -Jeremy
>
> On Mon, Nov 3, 2008 at 9:22 AM, Michael Dick <mi...@gmail.com>
> wrote:
> > Have you tried
> > <jta-data-source>java:comp/env/jdbc/workflowdb</jta-data-source> instead
> of
> > the property for openjpa.ConnectionFactoryName?
> >
> > -mike
> >
> > On Mon, Nov 3, 2008 at 8:22 AM, Håkon Sagehaug
> > <Ha...@bccs.uib.no>wrote:
> >
> >> Hi all,
> >>
> >> I've got a axis2 web service that is deployed in tomcat and talk to a
> >> database using openjpa. This works fine when I just use the persistent
> xml
> >> to configure my db connection, but now I want to use tomcat to configure
> >> the
> >> datasource. Here is my set-up
> >>
> >> persistent.xml
> >>
> >>
> >> <persistence-unit name="MyOpenJPa" transaction-type="RESOURCE_LOCAL">
> >>
> >>
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
> >>
> >> <class>demo.hibernate.MyPerson</class>
> >> <properties>
> >> <property name="openjpa.ConnectionFactoryName"
> >> value="java:comp/env/jdbc/workflowdb" />
> >> <property name="openjpa.Log" value="DefaultLevel=INFO,
> >> Tool=INFO" />
> >> <property name="openjpa.Sequence"
> >> value="table(Table=OPENJPA_SEQUENCE_TABLE, Increment=1)"/>
> >>
> >> </properties>
> >> </persistence-unit>
> >>
> >> In tomcat's service xml I've got this
> >>
> >> <Resource name="jdbc/workflowdb" auth="Container"
> >> type="javax.sql.DataSource"
> >> maxActive="5" maxIdle="5" maxWait="10000"
> >> username="name" password="password"
> >> driverClassName="org.postgresql.Driver"
> >> url="jdbc:postgresql://hostname/Workflows"/>
> >>
> >> I tried to put it into the <GlobalNamingResources> tag and inside a
> >> <Context> tag using the axis2 as path, but I always get this error back
> >>
> >> A JDBC Driver or DataSource class name must be specified in the
> >> ConnectionDriverName property.
> >>
> >> Does anyone have a good tip on how to get this to work??
> >>
> >> cheers, Håkon
> >>
> >> --
> >> Håkon Sagehaug, Software Developer
> >> Parallab, Bergen Center for Computational Science (BCCS)
> >> UNIFOB AS (University of Bergen Research Company)
> >>
> >
>
--
Håkon Sagehaug, Software Developer
Parallab, Bergen Center for Computational Science (BCCS)
UNIFOB AS (University of Bergen Research Company)
Re: Using datasource from tomcat with openjpa
Posted by Jeremy Bauer <te...@gmail.com>.
You may also need to define a resource reference in your web.xml.
This link contains a good example on how to configure and use a data
source: http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html.
The configuration part is what is important for OpenJPA, since it
just looks up the data source via the JNDI name provided in the
<jta-data-source> element (as Mike pointed out).
-Jeremy
On Mon, Nov 3, 2008 at 9:22 AM, Michael Dick <mi...@gmail.com> wrote:
> Have you tried
> <jta-data-source>java:comp/env/jdbc/workflowdb</jta-data-source> instead of
> the property for openjpa.ConnectionFactoryName?
>
> -mike
>
> On Mon, Nov 3, 2008 at 8:22 AM, Håkon Sagehaug
> <Ha...@bccs.uib.no>wrote:
>
>> Hi all,
>>
>> I've got a axis2 web service that is deployed in tomcat and talk to a
>> database using openjpa. This works fine when I just use the persistent xml
>> to configure my db connection, but now I want to use tomcat to configure
>> the
>> datasource. Here is my set-up
>>
>> persistent.xml
>>
>>
>> <persistence-unit name="MyOpenJPa" transaction-type="RESOURCE_LOCAL">
>>
>> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>>
>> <class>demo.hibernate.MyPerson</class>
>> <properties>
>> <property name="openjpa.ConnectionFactoryName"
>> value="java:comp/env/jdbc/workflowdb" />
>> <property name="openjpa.Log" value="DefaultLevel=INFO,
>> Tool=INFO" />
>> <property name="openjpa.Sequence"
>> value="table(Table=OPENJPA_SEQUENCE_TABLE, Increment=1)"/>
>>
>> </properties>
>> </persistence-unit>
>>
>> In tomcat's service xml I've got this
>>
>> <Resource name="jdbc/workflowdb" auth="Container"
>> type="javax.sql.DataSource"
>> maxActive="5" maxIdle="5" maxWait="10000"
>> username="name" password="password"
>> driverClassName="org.postgresql.Driver"
>> url="jdbc:postgresql://hostname/Workflows"/>
>>
>> I tried to put it into the <GlobalNamingResources> tag and inside a
>> <Context> tag using the axis2 as path, but I always get this error back
>>
>> A JDBC Driver or DataSource class name must be specified in the
>> ConnectionDriverName property.
>>
>> Does anyone have a good tip on how to get this to work??
>>
>> cheers, Håkon
>>
>> --
>> Håkon Sagehaug, Software Developer
>> Parallab, Bergen Center for Computational Science (BCCS)
>> UNIFOB AS (University of Bergen Research Company)
>>
>
Re: Using datasource from tomcat with openjpa
Posted by Håkon Sagehaug <Ha...@bccs.uib.no>.
hi
Some more information
Since the ws is running inside axis2 i used this context tag configuration
in server.xml
<Context path="/axis2" docBase="axis2" debug="5" reloadable="true"
crossContext="true">
<Resource name="jdbc/workflowdb" auth="Container"
type="javax.sql.DataSource"
maxActive="5" maxIdle="5" maxWait="10000"
username="user" password="password"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://hostname/Workflows"/>
</Context>
2008/11/3 Håkon Sagehaug <Ha...@bccs.uib.no>
> Hi
>
> Yes I've tried this, but still gets the same message, any other hints ??
>
> I use openjpa 1.2.0 , tomcat 5.5.26 and axis2 1.3 if this is of use
>
> cheers, Håkon
>
> 2008/11/3 Michael Dick <mi...@gmail.com>
>
> Have you tried
>> <jta-data-source>java:comp/env/jdbc/workflowdb</jta-data-source> instead
>> of
>> the property for openjpa.ConnectionFactoryName?
>>
>> -mike
>>
>> On Mon, Nov 3, 2008 at 8:22 AM, Håkon Sagehaug
>> <Ha...@bccs.uib.no>wrote:
>>
>> > Hi all,
>> >
>> > I've got a axis2 web service that is deployed in tomcat and talk to a
>> > database using openjpa. This works fine when I just use the persistent
>> xml
>> > to configure my db connection, but now I want to use tomcat to configure
>> > the
>> > datasource. Here is my set-up
>> >
>> > persistent.xml
>> >
>> >
>> > <persistence-unit name="MyOpenJPa" transaction-type="RESOURCE_LOCAL">
>> >
>> >
>> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>> >
>> > <class>demo.hibernate.MyPerson</class>
>> > <properties>
>> > <property name="openjpa.ConnectionFactoryName"
>> > value="java:comp/env/jdbc/workflowdb" />
>> > <property name="openjpa.Log" value="DefaultLevel=INFO,
>> > Tool=INFO" />
>> > <property name="openjpa.Sequence"
>> > value="table(Table=OPENJPA_SEQUENCE_TABLE, Increment=1)"/>
>> >
>> > </properties>
>> > </persistence-unit>
>> >
>> > In tomcat's service xml I've got this
>> >
>> > <Resource name="jdbc/workflowdb" auth="Container"
>> > type="javax.sql.DataSource"
>> > maxActive="5" maxIdle="5" maxWait="10000"
>> > username="name" password="password"
>> > driverClassName="org.postgresql.Driver"
>> > url="jdbc:postgresql://hostname/Workflows"/>
>> >
>> > I tried to put it into the <GlobalNamingResources> tag and inside a
>> > <Context> tag using the axis2 as path, but I always get this error back
>> >
>> > A JDBC Driver or DataSource class name must be specified in the
>> > ConnectionDriverName property.
>> >
>> > Does anyone have a good tip on how to get this to work??
>> >
>> > cheers, Håkon
>> >
>> > --
>> > Håkon Sagehaug, Software Developer
>> > Parallab, Bergen Center for Computational Science (BCCS)
>> > UNIFOB AS (University of Bergen Research Company)
>> >
>>
>
>
>
> --
> Håkon Sagehaug, Software Developer
> Parallab, Bergen Center for Computational Science (BCCS)
> UNIFOB AS (University of Bergen Research Company)
>
--
Håkon Sagehaug, Software Developer
Parallab, Bergen Center for Computational Science (BCCS)
UNIFOB AS (University of Bergen Research Company)
Re: Using datasource from tomcat with openjpa
Posted by Håkon Sagehaug <Ha...@bccs.uib.no>.
Hi
Yes I've tried this, but still gets the same message, any other hints ??
I use openjpa 1.2.0 , tomcat 5.5.26 and axis2 1.3 if this is of use
cheers, Håkon
2008/11/3 Michael Dick <mi...@gmail.com>
> Have you tried
> <jta-data-source>java:comp/env/jdbc/workflowdb</jta-data-source> instead of
> the property for openjpa.ConnectionFactoryName?
>
> -mike
>
> On Mon, Nov 3, 2008 at 8:22 AM, Håkon Sagehaug
> <Ha...@bccs.uib.no>wrote:
>
> > Hi all,
> >
> > I've got a axis2 web service that is deployed in tomcat and talk to a
> > database using openjpa. This works fine when I just use the persistent
> xml
> > to configure my db connection, but now I want to use tomcat to configure
> > the
> > datasource. Here is my set-up
> >
> > persistent.xml
> >
> >
> > <persistence-unit name="MyOpenJPa" transaction-type="RESOURCE_LOCAL">
> >
> >
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
> >
> > <class>demo.hibernate.MyPerson</class>
> > <properties>
> > <property name="openjpa.ConnectionFactoryName"
> > value="java:comp/env/jdbc/workflowdb" />
> > <property name="openjpa.Log" value="DefaultLevel=INFO,
> > Tool=INFO" />
> > <property name="openjpa.Sequence"
> > value="table(Table=OPENJPA_SEQUENCE_TABLE, Increment=1)"/>
> >
> > </properties>
> > </persistence-unit>
> >
> > In tomcat's service xml I've got this
> >
> > <Resource name="jdbc/workflowdb" auth="Container"
> > type="javax.sql.DataSource"
> > maxActive="5" maxIdle="5" maxWait="10000"
> > username="name" password="password"
> > driverClassName="org.postgresql.Driver"
> > url="jdbc:postgresql://hostname/Workflows"/>
> >
> > I tried to put it into the <GlobalNamingResources> tag and inside a
> > <Context> tag using the axis2 as path, but I always get this error back
> >
> > A JDBC Driver or DataSource class name must be specified in the
> > ConnectionDriverName property.
> >
> > Does anyone have a good tip on how to get this to work??
> >
> > cheers, Håkon
> >
> > --
> > Håkon Sagehaug, Software Developer
> > Parallab, Bergen Center for Computational Science (BCCS)
> > UNIFOB AS (University of Bergen Research Company)
> >
>
--
Håkon Sagehaug, Software Developer
Parallab, Bergen Center for Computational Science (BCCS)
UNIFOB AS (University of Bergen Research Company)
Re: Using datasource from tomcat with openjpa
Posted by Michael Dick <mi...@gmail.com>.
Have you tried
<jta-data-source>java:comp/env/jdbc/workflowdb</jta-data-source> instead of
the property for openjpa.ConnectionFactoryName?
-mike
On Mon, Nov 3, 2008 at 8:22 AM, Håkon Sagehaug
<Ha...@bccs.uib.no>wrote:
> Hi all,
>
> I've got a axis2 web service that is deployed in tomcat and talk to a
> database using openjpa. This works fine when I just use the persistent xml
> to configure my db connection, but now I want to use tomcat to configure
> the
> datasource. Here is my set-up
>
> persistent.xml
>
>
> <persistence-unit name="MyOpenJPa" transaction-type="RESOURCE_LOCAL">
>
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>
> <class>demo.hibernate.MyPerson</class>
> <properties>
> <property name="openjpa.ConnectionFactoryName"
> value="java:comp/env/jdbc/workflowdb" />
> <property name="openjpa.Log" value="DefaultLevel=INFO,
> Tool=INFO" />
> <property name="openjpa.Sequence"
> value="table(Table=OPENJPA_SEQUENCE_TABLE, Increment=1)"/>
>
> </properties>
> </persistence-unit>
>
> In tomcat's service xml I've got this
>
> <Resource name="jdbc/workflowdb" auth="Container"
> type="javax.sql.DataSource"
> maxActive="5" maxIdle="5" maxWait="10000"
> username="name" password="password"
> driverClassName="org.postgresql.Driver"
> url="jdbc:postgresql://hostname/Workflows"/>
>
> I tried to put it into the <GlobalNamingResources> tag and inside a
> <Context> tag using the axis2 as path, but I always get this error back
>
> A JDBC Driver or DataSource class name must be specified in the
> ConnectionDriverName property.
>
> Does anyone have a good tip on how to get this to work??
>
> cheers, Håkon
>
> --
> Håkon Sagehaug, Software Developer
> Parallab, Bergen Center for Computational Science (BCCS)
> UNIFOB AS (University of Bergen Research Company)
>