JPA – must be in the connectiondrivername property “how do I resolve it?” Specify the jdbc driver or datasource class name in
•
Java
Overview: This is my first WebSphere 7 server & amp; JPA 1.0 & EJB & Derby database
Second: This is 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: part of the code of the 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 beginning of the problem
@Stateful CartBean implements Cart{ .... .... public List<Item> getItems() { javax.persistence.Query query = em.createNamedQuery("getItem");//the problem here return query.getResultList(); } }
This is an error message: the jdbc driver or datasource class name must be specified in the connectiondrivername property How to solve this problem?
Solution
If you refer to a data source by JNDI name, you do not need to use openjpa Connectiondrivername property
One possible cause of this problem is persistence XML is in the wrong location The file must be located in the root directory of [class context] / meta inf For War file, the content should be similar to:
(foo.war) WEB-INF/classes/Meta-INF/persistence.xml WEB-INF/classes/com/foo123/jpa/Project.class WEB-INF/web.xml index.jsp
For A library packaged in a war file Jar 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
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码