Hi,
I'm trying to use Hibernate throught the JPA standard (EntityManager).
It's a very basic example - using Java SE , default mapping, no relationships.
I get the following exception:
Code:
Exception in thread "main" java.lang.NoSuchMethodError: org.hibernate.cfg.AnnotationConfiguration.getReflectionManager()Lorg/hibernate/annotations/common/reflection/ReflectionManager;
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:152)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:888)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:186)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:246)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
at company.EmpTest1.main(EmpTest1.java:27)
I tried running "javap" on your jar classes, and if I'm not mistaken the problem might be that method AnnotationConfiguration.getReflectionManager() actually return a result of type "org.hibernate.reflection.ReflectionManager", while EventListenerConfigurator.configure() assumes it returns "org.hibernate.annotations.common.reflection.ReflectionManager".
Could you please tell how to solve this?
Thanks very much :)
Additional details, just in case:
1. My classpath contains the following (downloaded today from your site):
Code:
- hibernate-3.2.5.ga (main jar + all jars from the 'lib' directory of your zipped distribution)
- hibernate-annotations-3.2.1.GA (ditto)
- hibernate-entitymanager-3.3.1.GA (ditto)
2. My "META-INF/persistence.xml":
Code:
<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_1_0.xsd"
version="1.0">
<persistence-unit name="unit1" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>company.Employee</class>
<properties>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.url" value="mysql://localhost:3306/test"/>
<property name="hibernate.connection.username" value="myUser"/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.max_fetch_depth" value="3"/>
</properties>
</persistence-unit>
</persistence>
3. My code:
Code:
// The entity:
package company;
@Entity
public class Employee {
@Id
private int id;
private String name;
...
}
// The main method:
public static void main(Stringp[] args) throws Exception{
EntityManagerFactory emf= Persistence.createEntityManagerFactor("unit1");
EntityManager em= emFact.createEntityManager();
Employee emp=new Employee(22, "john");
em.getTransaction().begin();
em.persist(emp);
em.getTransaction().commit();
}
Thanks.