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

DataNucleus
  • 15,497
  • 3
  • 32
  • 37
Vicky
  • 16,679
  • 54
  • 139
  • 232
  • What if I want to use non-jta transactions ??? the post you point explains about JTA transactions only.. – Vicky Oct 17 '11 at 09:16
  • 2
    You set your persistence provider to Hibernate, yet want to use OpenJPA ? You don't set JPA standard properties for connection driver/URL/user/password. – DataNucleus Oct 17 '11 at 15:25
  • @DataNucleus Where did he say he **wanted** to use OpenJPA? – MaDa Oct 20 '11 at 07:50

2 Answers2

1

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.

Community
  • 1
  • 1
MaDa
  • 10,511
  • 9
  • 46
  • 84
  • Is it ok to use Hibernate 3.6 or 3.5 but only the JPA 1.0 components ? like i will not use criteriabuilder but only named queries. Will that help ??? – Vicky Oct 20 '11 at 08:16
  • Also, a stack overflow related question --- For someone very new to hibernate, spring, websphere, etc., the error I am getting is a valid error. Also, I have provided all the details clearly while asking the question. Still my question is voted down ?? Why ?? This doesn't help newbies like us because StackOverflow blocks us for posting our silly (for others) but valid questions if our questions are voted down!! – Vicky Oct 20 '11 at 08:18
  • @NikunjChauhan 1. No, you need to downgrade your Hibernate version, even if you don't plan to use JPA2 enhancements. 2. I don't know, really. Your question is quite well developed, and to the point. I gave it +1. Don't give up, SO is open to morons and geniuses at the same time. Like anywhere in life. – MaDa Oct 20 '11 at 09:08
-1

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.

James DW
  • 1,815
  • 16
  • 21
  • -1. The guy's trying to use Hibernate, which is a perfectly valid intention. Why would he want to switch to OpenJPA properties? The error he gets is because Websphere's built-in OpenJPA provider gets initialized. – MaDa Oct 20 '11 at 07:47
  • @MaDa The original post, which has since been editted, mentioned that he wanted to use OpenJPA. Thanks anyway mate! Note comments on the post above! – James DW Oct 20 '11 at 08:16
  • @JamesDW Please edit your answer then, it's impossible to revert the vote unless the answer has been edited. – MaDa Oct 21 '11 at 07:40