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?
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