概述:这是我的第一篇Websphere 7 Server& amp; JPA 1.0& EJB&德比数据库.
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>
第三:Item实体Class的部分代码
@Entity @Table(schema = "SHOP",name = "ITEM") @NamedQuery(name = "getItem",query = "SELECT i FROM Item i") public class Item{...}
第四:这里是业务类CartBean,这里是问题的开始
@Stateful CartBean implements Cart{ .... .... public List<Item> getItems() { javax.persistence.Query query = em.createNamedQuery("getItem");//the problem here return query.getResultList(); } }
这是错误消息:必须在ConnectionDriverName属性中指定JDBC驱动程序或DataSource类名.
如何解决这个问题?
解决方法
如果您通过JNDI名称引用数据源,则不需要使用openjpa.ConnectionDriverName属性.
导致此问题的一个可能原因是persistence.xml位于错误的位置.该文件必须位于[类上下文] / Meta-INF的根目录.对于.war文件,内容应类似于:
(foo.war) WEB-INF/classes/Meta-INF/persistence.xml WEB-INF/classes/com/foo123/jpa/Project.class WEB-INF/web.xml index.jsp
(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