You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geronimo.apache.org by brianm709 <bm...@dstsystems.com> on 2007/12/19 19:05:36 UTC

Accessing SQL Server datasource from EJB

I am new to Geronimo.  I started with the Very simple Entity EJB example
http://cwiki.apache.org/GMOxDOC20/very-simple-entity-ejb-example.html

Everything is working fine using derby as the DB.
My next step is to use a SQL Server database.
I configured a database pool named "myawddb2".  It connects successfully.

I followed the "Untested Instructions for using jta-datasource in
persistence.xml" at the bottom of the example

I added the myawddb2 dependency to my openejb-jar.xml

<openejb-jar
      xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1" 
      xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.1" 
      xmlns:pkgen="http://www.openejb.org/xml/ns/pkgen-2.0" 
      xmlns:sec="http://geronimo.apache.org/xml/ns/security-1.1" 
      xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2">
   <sys:environment>
      <sys:moduleId>
         <sys:groupId>org.apache.geronimo.samples</sys:groupId>
         <sys:artifactId>MyPhonebookBean</sys:artifactId>
         <sys:version>1.0</sys:version>
         <sys:type>car</sys:type>
      </sys:moduleId>
     
      <sys:dependencies>
         <sys:dependency>
            <sys:groupId>console.dbpool</sys:groupId>
            <sys:artifactId>myawddb2</sys:artifactId>
            <sys:version>1.0</sys:version>
            <sys:type>rar</sys:type>
         </sys:dependency>
      </sys:dependencies>
      
   </sys:environment>
</openejb-jar>

I modified the persistence unit in my persistence.xml

<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="myawddbPU">
      <description>Phone Book</description>
      <jta-datasource>myawddb2</jta-datasource>  
      <class>org.apache.geronimo.samples.myphonebookpak.PhoneBook</class>
      <properties>
         <property name="openjpa.jdbc.SynchronizeMappings" value="false" />
      </properties>
   </persistence-unit>  
</persistence>

The app deploys successfully.
When I test it I get the following exception:
11:44:42,532 ERROR [OpenEJB] The bean instances business method encountered
a system exception: A JDBC Driver or DataSource class name must be specified
in the ConnectionDriverName property.
<openjpa-1.0.0-r420667:568756 fatal user error>
org.apache.openjpa.persistence.ArgumentException: A JDBC Driver or
DataSource class name must be specified in the ConnectionDriverName
property.

I tried adding the openjpa.ConnectionDriverName property to my
persistence.xml file, although I think this should come from the datasource
I have already defined.  When I do this I get a "The connection URL is
null." error.

I am looking for any guidance that might help me through this issue.

Thanks.
Brian
-- 
View this message in context: http://www.nabble.com/Accessing-SQL-Server-datasource-from-EJB-tp14422136s134p14422136.html
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.


Re: Accessing SQL Server datasource from EJB

Posted by brianm709 <bm...@dstsystems.com>.
I am using geronimo-tomcat6-jee5-2.0.2.
I was able to get it to work by explicitly setting the database properties
in my persistence.xml.
This will work for me for now, but I would prefer to use a datasource.

<?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="myawddbPU">
      <description>Phone Book</description>
      <class>org.apache.geronimo.samples.myphonebookpak.PhoneBook</class>
      <properties>
         <property name="openjpa.ConnectionURL"
value="jdbc:sqlserver://10.193.204.139:1433;DatabaseName=AWDP_32" />
         <property name="openjpa.ConnectionDriverName"
value="com.microsoft.sqlserver.jdbc.SQLServerDriver " />
         <property name="openjpa.ConnectionUserName" value="XXXXX" />
         <property name="openjpa.ConnectionPassword" value="XXXXXXXX" />
         <property name="openjpa.jdbc.SynchronizeMappings" value="false" />
      </properties>
   </persistence-unit> 

</persistence>

Thanks
-- 
View this message in context: http://www.nabble.com/Accessing-SQL-Server-datasource-from-EJB-tp14422136s134p14424671.html
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.


Re: Accessing SQL Server datasource from EJB

Posted by David Jencks <da...@yahoo.com>.
I'm a bit mystified so far.  Which geronimo version are you using?   
You might try the current 2.1-SNAPSHOT which I think you can get from  
http://people.apache.org/~prasad/binaries/trunk/20071218

You might try:
including a non-jta-datasource (you'll need to set up an additional  
datasource that has <no-transaction>)
explicitly setting the DBDictionary for MSSQL in the persistence.xml  
properties

but I don't really see how these would cause this problem.

still thinking...
david jencks

On Dec 19, 2007, at 10:05 AM, brianm709 wrote:

>
> I am new to Geronimo.  I started with the Very simple Entity EJB  
> example
> http://cwiki.apache.org/GMOxDOC20/very-simple-entity-ejb-example.html
>
> Everything is working fine using derby as the DB.
> My next step is to use a SQL Server database.
> I configured a database pool named "myawddb2".  It connects  
> successfully.
>
> I followed the "Untested Instructions for using jta-datasource in
> persistence.xml" at the bottom of the example
>
> I added the myawddb2 dependency to my openejb-jar.xml
>
> <openejb-jar
>       xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1"
>       xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.1"
>       xmlns:pkgen="http://www.openejb.org/xml/ns/pkgen-2.0"
>       xmlns:sec="http://geronimo.apache.org/xml/ns/security-1.1"
>       xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2">
>    <sys:environment>
>       <sys:moduleId>
>          <sys:groupId>org.apache.geronimo.samples</sys:groupId>
>          <sys:artifactId>MyPhonebookBean</sys:artifactId>
>          <sys:version>1.0</sys:version>
>          <sys:type>car</sys:type>
>       </sys:moduleId>
>
>       <sys:dependencies>
>          <sys:dependency>
>             <sys:groupId>console.dbpool</sys:groupId>
>             <sys:artifactId>myawddb2</sys:artifactId>
>             <sys:version>1.0</sys:version>
>             <sys:type>rar</sys:type>
>          </sys:dependency>
>       </sys:dependencies>
>
>    </sys:environment>
> </openejb-jar>
>
> I modified the persistence unit in my persistence.xml
>
> <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="myawddbPU">
>       <description>Phone Book</description>
>       <jta-datasource>myawddb2</jta-datasource>
>       <class>org.apache.geronimo.samples.myphonebookpak.PhoneBook</ 
> class>
>       <properties>
>          <property name="openjpa.jdbc.SynchronizeMappings"  
> value="false" />
>       </properties>
>    </persistence-unit>
> </persistence>
>
> The app deploys successfully.
> When I test it I get the following exception:
> 11:44:42,532 ERROR [OpenEJB] The bean instances business method  
> encountered
> a system exception: A JDBC Driver or DataSource class name must be  
> specified
> in the ConnectionDriverName property.
> <openjpa-1.0.0-r420667:568756 fatal user error>
> org.apache.openjpa.persistence.ArgumentException: A JDBC Driver or
> DataSource class name must be specified in the ConnectionDriverName
> property.
>
> I tried adding the openjpa.ConnectionDriverName property to my
> persistence.xml file, although I think this should come from the  
> datasource
> I have already defined.  When I do this I get a "The connection URL is
> null." error.
>
> I am looking for any guidance that might help me through this issue.
>
> Thanks.
> Brian
> -- 
> View this message in context: http://www.nabble.com/Accessing-SQL- 
> Server-datasource-from-EJB-tp14422136s134p14422136.html
> Sent from the Apache Geronimo - Users mailing list archive at  
> Nabble.com.
>