0

Can someone please provide me with a sample minimalist persistence.xml file that works and how to get it working in code? I am following this document which has frustrating gaps: Hibernate Setup.

I have this but

<persistence 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_2_0.xsd"
        version="2.0">
  <persistence-unit name="manager1" transaction-type="JTA">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.SybaseDialect"/>       
      </properties>
    </persistence-unit>
</persistence>

When I step through this line in my code:

Session session = HibernateUtil.getSessionFactory().openSession();    

The following exception is thrown.

Initial SessionFactory creation failed.java.lang.ClassCastException: org.hibernate.annotations.common.reflection.java.JavaReflectionManager cannot be cast to org.hibernate.annotations.common.reflection.MetadataProviderInjector
Klaus Nji
  • 18,107
  • 29
  • 105
  • 185

2 Answers2

0

This is how I do it with EclipseLink. Hope it sparks some idea for you.

JPA - Using Multiple data sources to define access control

Community
  • 1
  • 1
gnowlak
  • 486
  • 1
  • 6
  • 12
0

Answer was provided by this link: solution here

POM.xml contained references I needed to run Hibernate with JPA as follows:

 <dependency>
           <groupId>org.hibernate</groupId>
           <artifactId>hibernate-core</artifactId>
           <version>4.1.1.Final</version>
        </dependency>
        <dependency>
           <groupId>org.hibernate</groupId>
           <artifactId>hibernate-entitymanager</artifactId>
           <version>3.4.0.GA</version>
         </dependency>
           <dependency>
             <groupId>org.hibernate</groupId>
              <artifactId>hibernate-validator</artifactId>
              <version>4.3.0.Final</version>
           </dependency>

To use JPA, I had to clean things up to look like this:

org.hibernate hibernate-entitymanager ${hibernate-core-version} org.hibernate hibernate-validator ${hibernate-validator-version}

using the following properties:

<hibernate.version>4.1.4.Final</hibernate.version>
<hibernate.validator.version>4.3.0.Final</hibernate.validator.version>

This took me one step forward.

Klaus Nji
  • 18,107
  • 29
  • 105
  • 185