-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: No Persistence provider for EntityManager
PostPosted: Sat Feb 26, 2011 4:53 am 
Newbie

Joined: Tue Feb 22, 2011 12:50 am
Posts: 2
I am trying to use JPA with eclipselink. It worked fine.
To check the behaviour with JPA with hibernate as persistence provider, I changed the persitence.xml and I am getting the infamous error "No Persistence provider for EntityManager named usinghibernate"

peristence.xml

Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
  <persistence-unit name="usinghibernate">
    <provider>org.hibernate.ejb.HibernatePeristence</provider>
    <class>arun.ucerelay.datastructures.XVMUpdateProfile</class>
    <class>arun.ucerelay.datastructures.XVMUpdateProfileItem</class>

    <!-- Scan for annotated classes and Hibernate mapping XML files -->
    <properties>
       <property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver"/>
       <property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:krsna"/>
       <property name="hibernate.connection.username" value="scott"/>
       <property name="hibernate.connection.password" value="tiger"/>
       <property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect"/>
       <property name="hibernate.show_sql" value="true"/>
    </properties>
  </persistence-unit>
</persistence>


Java program:

Code:
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

import arun.ucerelay.datastructures.XVMUpdateProfile;
   

public class UpdateProfileMain {
    
     private static Logger logger = MyLogger.getLogger(UpdateProfileMain.class.getName());
     
       public static void main(String args[]) {
           List<XVMUpdateProfile> profiles = new ArrayList<XVMUpdateProfile>();
            try {
    
               EntityManagerFactory emf = Persistence.createEntityManagerFactory("usinghibernate");
                
                // First unit of work
                EntityManager em = emf.createEntityManager();
                
               EntityTransaction etx = em.getTransaction();
                etx.begin();
                profiles = em.createQuery("select profile from XVMUpdateProfile profile order by profile.profileId asc").getResultList();
                
                logger.info( profiles.size() + " profiles found by Arun. ");
                
                etx.commit();
                em.close();
            }catch(Exception ex){
               logger.log(Level.WARNING, " Arun Could not load profiles : " + ex.getMessage());
               logger.log(Level.WARNING, " Arun Could not load profiles : " + ex.getCause());
            }          
   }
}


Here is what I did to get hibernate jars :
I included 2 dependencies in maven pom.xml :
Code:
   ...
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-entitymanager</artifactId>
      <version>3.5.6-Final</version>
    </dependency>
   
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>1.5.2</version>
    </dependency>
   ...



In the logs, its clear that it is able to find META-INF/persistence.xml and persistence unit and again it complains that it doesnt find the persistence unit.

Code:
TRACE 2011-02-26 00:50:31,765 [main](PersistenceXmlLoader.java:112) org.hibernate.ejb.packaging.PersistenceXmlLoader - Validate with persistence_2_0.xsd schema on file file:/C:/arun/eclipse/workspace/practicewitheclipselink/target/classes/META-INF/persistence.xml
TRACE 2011-02-26 00:50:31,781 [main](PersistenceXmlLoader.java:117) org.hibernate.ejb.packaging.PersistenceXmlLoader - Found error with persistence_2_0.xsd schema on file file:/C:/arun/eclipse/workspace/practicewitheclipselink/target/classes/META-INF/persistence.xml
TRACE 2011-02-26 00:50:31,781 [main](PersistenceXmlLoader.java:127) org.hibernate.ejb.packaging.PersistenceXmlLoader - Validate with persistence_1_0.xsd schema on file file:/C:/arun/eclipse/workspace/practicewitheclipselink/target/classes/META-INF/persistence.xml
TRACE 2011-02-26 00:50:31,781 [main](PersistenceXmlLoader.java:239) org.hibernate.ejb.packaging.PersistenceXmlLoader - Persistent Unit name from persistence.xml: usinghibernate
TRACE 2011-02-26 00:50:31,781 [main](Ejb3Configuration.java:321) org.hibernate.ejb.Ejb3Configuration - PersistenceMetadata(version=1.0) [
   name: usinghibernate
   jtaDataSource: null
   nonJtaDataSource: null
   transactionType: RESOURCE_LOCAL
   provider: org.hibernate.ejb.HibernatePeristence
   useQuotedIdentifiers: false
   classes[
      arun.ucerelay.datastructures.XVMUpdateProfile      arun.ucerelay.datastructures.XVMUpdateProfileItem   ]
   packages[
   ]
   mappingFiles[
   ]
   jarFiles[
   ]
   hbmfiles: 0
   properties[
      hibernate.connection.username: scott
      hibernate.connection.password: tiger
      hibernate.dialect: org.hibernate.dialect.OracleDialect
      hibernate.show_sql: true
      hibernate.connection.url: jdbc:oracle:thin:@localhost:1521:krsna
      hibernate.connection.driver_class: oracle.jdbc.driver.OracleDriver
   ]]
Feb 26, 2011 12:50:31 AM UpdateProfileMain main
WARNING:  Arun Could not load profiles : No Persistence provider for EntityManager named usinghibernate
Feb 26, 2011 12:50:31 AM UpdateProfileMain main
WARNING:  Arun Could not load profiles : null


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.