A JDBC Driver or DataSource class name must be specified in the ConnectionDriverName property "How to solve it?"
Asked Answered
D

7

7

overview : This my first tutorial by Websphere 7 Server & JPA 1.0 & EJB & Derby Database.

First : My data source name is EJB3BANK & my target database is SHOP .

Second : This the persistence.xml file

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="ShopJPA" transaction-type="JTA">
    <jta-data-source>jdbc/EJB3BANK</jta-data-source>
    <non-jta-data-source>jdbc/EJB3BANK</non-jta-data-source>
    <properties>
        <property name="openjpa.jdbc.Schema" value="SHOP" />
    </properties>
</persistence-unit>
</persistence> 

Third : This partial code of Item entity Class

@Entity
@Table(schema = "SHOP", name = "ITEM")
@NamedQuery(name = "getItem", query = "SELECT i FROM Item i")
public class Item{...}

Fourth : here is the business class CartBean here is the start of the problem

@Stateful
CartBean implements Cart{
....
....
public List<Item> getItems() {      
javax.persistence.Query query = em.createNamedQuery("getItem");//the problem here
return query.getResultList();
}
}

and This is the error message: A JDBC Driver or DataSource class name must be specified in the ConnectionDriverName property. How to resolve this problem?

Dekameter answered 4/6, 2011 at 14:31 Comment(4)
The displayed error message indicates that the data source is unavailable or has not been configured properly in WebSphere 7. Have you verified this?Mismate
@Vineet I maked data source in RAD named EJB3BANK and it's working fine... but if I understand you right do you mean configure EJB3BANK data source also in Administration console of WebSphere??Dekameter
Yes, that's what I meant. Is it available at runtime? See this related question at the developerWorks forum.Mismate
Showing the full stack trace might be useful to some.Alwin
S
11

Used openjpa.ConnectionDriverName property is not needed if you are referring to data source by JNDI name.

One possible cause for this issue is that persistence.xml is in the wrong location. The file must be located at the [root of class context]/META-INF. For a .war file, contents should be something like:

(foo.war)
WEB-INF/classes/META-INF/persistence.xml
WEB-INF/classes/com/foo123/jpa/Project.class
WEB-INF/web.xml
index.jsp

and for a library .jar file packaged inside a .war file:

(foo.war)
WEB-INF/lib/my-library.jar
WEB-INF/web.xml
index.jsp

(my-library.jar)
META-INF/persistence.xml
com/foo123/jpa/Project.class
Stereotomy answered 12/10, 2011 at 19:35 Comment(0)
P
3

the jpa message

A JDBC Driver or DataSource class name must be specified in the ConnectionDriverName property

is a misleading message. Doesn't help to understand the problem. It would be better something like:

the jta-data-source is jdbc/EJB3BANK is unavailable/unreachable

because it's what is happening. Maybe you have included a jpa project in a web or ejb project (or maybe not, you could had added the jpa facets directly to one of this kind of project) however, once you have created the jdbc connection on the webshpere console the best way to use it is:

  1. change your persistence.xml (AnyJpaProject/src/META-INF/persistence.xml)

    <jta-data-source>java:comp/env/jdbc/EJB3BANK</jta-data-source>
    
  2. ensure your web.xml/ejb-jar.xml has something like:

    <resource-ref>
        <description></description>
        <res-ref-name>jdbc/EJB3BANK</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref> 
    
  3. add in ibm-ejb-jar-bnd.xml/ibm-web-bnd.xml:

<resource-ref name="jdbc/EJB3BAN" binding-name="jdbc/EJB3BAN">

Hope this help.

Privateer answered 19/4, 2016 at 9:48 Comment(1)
Perhaps @Dekameter can mark this answer as correct this seems to be it.Reich
R
2

I think this is a bug on the implementation of the JPA provider. I am getting a similar error, but in my case I actually didn't put in the data-source name. The reason being is the standards allow for the concept of a default datasource. Unfortunately it does not work well with WebSphere Application Server 8.0.0.1 nor RSA 8.0. Not sure if a PMR has been filed either.

Reich answered 10/11, 2011 at 5:53 Comment(0)
B
1

Just to add to eis's answer (apologies, don't have enough rep to comment):

Using Eclipse my persistence.xml was initially located in the root src folder src/persistence.xml

Moving it to src/META-INF/persistence.xml fixed my issue as Eclipse automatically now moves it to the build directory.

Not all ORM (object relational mapping) APIs work like this though, I'm pretty sure using Hibernate my hibernate.cfg.xml (persistence.xml) was always just directly in the "src" folder.

Brand answered 30/6, 2013 at 21:46 Comment(0)
C
1

It is a bug not to be able to use the datasource name in the persistence.xml after adding the datasoruce in the application server. However, it will work if you add the properties in the persistence.xml as below.

    <property name="openjpa.ConnectionURL" value="DB URL"/>
    <property name="openjpa.ConnectionDriverName" value="Driver Name"/>
    <property name="openjpa.ConnectionUserName" value="userid"/>
    <property name="openjpa.ConnectionPassword" value="password"/>
Cordiform answered 22/1, 2016 at 19:25 Comment(0)
L
0

I think, what you are trying to do is to define a new Datasource by declaring it in the persistence.xml and it is missing a property like <property name="openjpa.ConnectionDriverName" value="org.apache.derby.jdbc.EmbeddedDriver" />

However as you are using Websphere I would suggest you to create the Datasource via Webspheres Administration Console (Webinterface). Under Resources->JDBC you would first create a JDBC Provider and tell it to use the Derby Driver. And after that you would create a new Datasource using this provider. There you can define the JNDI-binding. Set it to jdbc/EJB3BANK. And you current persistence.xml should work hos it is supposed to.

Lues answered 17/6, 2011 at 8:39 Comment(0)
M
0

try this men:

 <persistence-unit name="ShopJPA" transaction-type="JTA">
     <jta-data-source>jdbc/EJB3BANK</jta-data-source>
     <non-jta-data-source>jdbc/EJB3BANK</non-jta-data-source>
     <class>jdbc/EJB3BANK</class>
     <properties>
         <property name="openjpa.jdbc.Schema" value="SHOP" />
     </properties>
 </persistence-unit>
 </persistence> 

I don't know if must be "jdbc/EJB3BANK" or only "EJB3BANK" in the node class, try the two options. =D It works for my

Melnick answered 18/8, 2014 at 23:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.