1

I am new to JPA & hibernate, when I try this tutorial . I added the following provider in my persistence.xml,

<provider>org.hibernate.ejb.HibernatePersistence</provider> 

and I am getting this error..

log4j:WARN No appenders could be found for logger (org.jboss.logging).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" java.lang.NoSuchMethodError: org.hibernate.cfg.Configuration.addAnnotatedClass(Ljava/lang/Class;)Lorg/hibernate/cfg/Configuration;
    at org.hibernate.ejb.Ejb3Configuration.addAnnotatedClass(Ejb3Configuration.java:1421)
    at org.hibernate.ejb.Ejb3Configuration.addNamedAnnotatedClasses(Ejb3Configuration.java:1391)
    at org.hibernate.ejb.Ejb3Configuration.addClassesToSessionFactory(Ejb3Configuration.java:1184)
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1048)
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:291)
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:373)
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
    at de.vogella.jpa.simple.main.Main.main(Main.java:17)

Kindly help to resolve this error . Thank you

Nazik
  • 8,696
  • 27
  • 77
  • 123
Bhushan
  • 287
  • 3
  • 6
  • 16

4 Answers4

5

Check your version of Hibernate, you need hibernate-core 3.6.0 or higher to use the method addAnnotatedClass of org.hibernate.cfg.Configuration

overmeulen
  • 1,158
  • 6
  • 15
4

It look like the Hibernate Annotation jar is wrong. It is not compatible with the jar version. So that is why it showing the "java.lang.NoSuchMethodError"

Could you please tell me the which jar version are you currently working , please specify the version ? Then only we have to easily address this.

Which Hibernate version are you currently working ?

Which Annotation version are you currently working ?

please specify the version. Thanks.

  • org.hibernate hibernate-core 4.2.0.CR1 org.hibernate hibernate-commons-annotations 3.2.0.Final – Bhushan Feb 19 '13 at 14:06
  • thanks for your reply.. here is some dependency i have used, org.hibernate hibernate-core 4.2.0.CR1 org.hibernate hibernate-commons-annotations 3.2.0.Final – Bhushan Feb 19 '13 at 14:15
  • wait i will check and let you know that. – Adalarasan_Serangulam Feb 19 '13 at 14:17
  • hibernate - 3.2.6.ga hibernate-annotations - 3.2.1.ga hibernate-commons-annotations - 3.0.0.ga hibernate-entitymanager - 3.2.1.ga – Adalarasan_Serangulam Feb 19 '13 at 14:21
  • update your annotataion jar and let me know that what happens. – Adalarasan_Serangulam Feb 19 '13 at 14:23
  • Thanks for solution, now it giving error.... Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:720) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60) at de.vogella.jpa.simple.main.Main.main(Main.java:17 – Bhushan Feb 20 '13 at 05:48
  • sir, kindly also help to resolve this...http://stackoverflow.com/questions/14976165/java-lang-noclassdeffounderror-could-not-initialize-class-net-sf-cglib-proxy-en/14976259#14976259 – Bhushan Feb 20 '13 at 09:28
  • @bhushan, you something missed on the class path. so that is why it shows the "MappableContainerException". Some classes are not loaded related to the DB Manager. – Adalarasan_Serangulam Feb 20 '13 at 09:40
1

In addition:

I've faced the same problem and I came to this page after googling for an answer and none of these answers helped me, so in case that somebody passes through the same problem:

I had an ArrayList<Entity> and when I wanted to add an item to the arraylist, the NoSuchMethodException encountered. The problem was that the ArrayList had to be an Array.

Memet Olsen
  • 4,578
  • 5
  • 40
  • 50
1

Use the following dependencies...

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>4.3.6.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>3.6.4.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-annotations</artifactId>
    <version>3.5.5-Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate.common</groupId>
    <artifactId>hibernate-commons-annotations</artifactId>
    <version>4.0.4.Final</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.7</version>
</dependency>
Pang
  • 9,564
  • 146
  • 81
  • 122