websphere 6.1中的OpenJPA错误

时间:2011-10-17 08:54:35

标签: hibernate jpa websphere openjpa

我的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上运行示例

任何提示,想法???

2 个答案:

答案 0 :(得分:1)

但是我在Hibernate配置中看不到任何明显的错误:

CriteriaBuilder cb = em.getCriteriaBuilder();

这说你正在尝试使用Hibernate 3.6或3.5,对吧?它符合JPA 2.0标准,这意味着:Websphere 6.1不兼容。有关详细信息,请参阅我的answers之一。您可能希望在应用程序启动时检查SystemOut.logSystemErr.log,您可能会在那里发现一些错误。

答案 1 :(得分:-1)

我会说这是因为您正在使用hibernate属性来设置驱动程序信息。

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

您需要找到OpenJPA等效项。