Мой файл persistence.xml выглядит примерно так:
<persistence-unit name="fruitManager" transaction-type="RESOURCE_LOCAL">
<!-- Hibernate as provider -->
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<!-- list your persistent classes here -->
<class>com.mypackage.Fruit</class>
<!-- any more classes if there-->
<properties>
<!-- DB2 UDB -->
<property name="hibernate.dialect" value="org.hibernate.dialect.DB2Dialect" />
<property name="hibernate.default_schema" value="MYSCHEMA" />
<!-- provide datasource properties -->
<property name="hibernate.connection.driver_class" value="com.ibm.db2.jcc.DB2Driver"></property>
<property name="hibernate.connection.username" value="abc"></property>
<property name="hibernate.connection.password" value="xyz"></property>
<property name="hibernate.connection.url" value="jdbc:db2://abc.xyz:50001/TESTDB"></property>
<property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" />
<property name="c3p0.acquire_increment" value="1"></property>
<property name="c3p0.idle_test_period" value="100"></property> <!-- seconds -->
<property name="c3p0.max_size" value="100"></property>
<property name="c3p0.max_statements" value="0"></property>
<property name="c3p0.min_size" value="10"></property>
<property name="c3p0.timeout" value="100"></property> <!-- seconds -->
<!-- For Debug mode, enable it until development -->
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.use_sql_comments" value="false" />
</properties>
</persistence-unit>
И мой класс сущности:
@Entity
public class Fruit {
@Id
int id;
String name;
String color;
}
В моем DAO код:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("fruitManager");
EntityManager em = emf.createEntityManager();
//get the criteria builder
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Fruit> c = cb.createQuery(Fruit.class);
Просто чтобы проверить, работает ли установка, я запускаю следующий простой запрос:
// get the count of the results first
CriteriaQuery<Long> cq = cb.createQuery(Long.class);
cq.select(cb.count(cq.from(Fruit.class)));
Long count = em.createQuery(cq).getSingleResult();
System.out.println("Number of fruits are: " + count);
Однако я получаю следующую ошибку:
[10/17/11 14:02:40:069 IST] 00000076 SystemErr R <openjpa-1.0.3-SNAPSHOT-r420667:649224 fatal user error> org.apache.openjpa.persistence.ArgumentException: A JDBC Driver or DataSource class name must be specified in the ConnectionDriverName property.
Я работаюпример на WAS 6.1
Любые подсказки, идеи ???