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 <[EMAIL PROTECTED]> 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 <
> [EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]>
> >
> >> 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 <[EMAIL PROTECTED]>
> >>
> >> 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 <[EMAIL PROTECTED]
> >
> >>> 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
> >>> > <[EMAIL PROTECTED]>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)
> >
>
>

Reply via email to