websphere 6.1 中的 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 上运行示例
有任何提示、想法吗???
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
但是,我在您的 Hibernate 配置中看不到任何明显的错误:
这表明您正在尝试使用 Hibernate 3.6 或 3.5,对吧?它符合 JPA 2.0 标准,这意味着:不符合 Websphere 6.1 标准。请参阅我的一个答案 了解更多详情。您可能需要在应用程序启动时检查
SystemOut.log
和SystemErr.log
,您可能会在那里发现一些错误。I can't see any evident errors in your Hibernate config, however:
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
andSystemErr.log
at the point when your application starts, you'll probably find some errors there.我想说这是因为您正在使用休眠属性来设置驱动程序信息。
您需要找到 OpenJPA 的等效项。
I'd say it's because you're using hibernate properties to set the driver information.
You will need to find the OpenJPA equivalents.