必须在ConnectionDriverName属性“如何解决它?”中指定JDBC驱动程序或DataSource类名。 [英] A JDBC Driver or DataSource class name must be specified in the ConnectionDriverName property "How to solve it?"

查看:1131
本文介绍了必须在ConnectionDriverName属性“如何解决它?”中指定JDBC驱动程序或DataSource类名。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

概述:这是我的第一篇Websphere 7 Server& amp; JPA 1.0& EJB& Derby数据库。

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


首先:我的数据源名称是EJB3BANK&我的目标数据库是SHOP。

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

第二:这是 persistence.xml 文件

<?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{...}

第四:这是商务舱 CartBean 这里是问题的开始

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();
}
}

这是错误消息: A必须在ConnectionDriverName属性中指定JDBC驱动程序或DataSource类名。
如何解决此问题?

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?

推荐答案

如果您指的是数据源,则不需要使用openjpa.ConnectionDriverName属性通过JNDI名称。

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

此问题的一个可能原因是persistence.xml位于错误的位置。该文件必须位于[类上下文] / META-INF的根目录。对于.war文件,内容应类似于:

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

以及打包在.war文件中的库.jar文件:

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

这篇关于必须在ConnectionDriverName属性“如何解决它?”中指定JDBC驱动程序或DataSource类名。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆