websphere 6.1 中的 OpenJPA 错误

发布于 2024-12-10 04:01:10 字数 3216 浏览 0 评论 0原文

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

有任何提示、想法吗???

My persistence.xml looks something like:

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

And my entity class is:

@Entity 
public class Fruit {     
@Id 
int id;     
String name;     
String color; 
} 

In my DAO the code is:

EntityManagerFactory emf = Persistence.createEntityManagerFactory("fruitManager");
EntityManager em = emf.createEntityManager();

//get the criteria builder
CriteriaBuilder cb = em.getCriteriaBuilder();

CriteriaQuery<Fruit> c = cb.createQuery(Fruit.class);

Just to test whether the setup is working or not, I am running the following simple query:

    // 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);

However, I am getting the following error:

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

I am running the example on WAS 6.1

Any hints, Ideas ???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

执手闯天涯 2024-12-17 04:01:10

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

CriteriaBuilder cb = em.getCriteriaBuilder();

这表明您正在尝试使用 Hibernate 3.6 或 3.5,对吧?它符合 JPA 2.0 标准,这意味着:不符合 Websphere 6.1 标准。请参阅我的一个答案 了解更多详情。您可能需要在应用程序启动时检查 SystemOut.logSystemErr.log,您可能会在那里发现一些错误。

I can't see any evident errors in your Hibernate config, however:

CriteriaBuilder cb = em.getCriteriaBuilder();

This says you're trying to use Hibernate 3.6 or 3.5, right? It's JPA 2.0-compliant, which means: Websphere 6.1 non-compliant. See one of my answers for more details. You might want to check your SystemOut.log and SystemErr.log at the point when your application starts, you'll probably find some errors there.

鸵鸟症 2024-12-17 04:01:10

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

<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 的等效项。

I'd say it's because you're using hibernate properties to set the driver information.

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

You will need to find the OpenJPA equivalents.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文