Hi all, I'm newbie to hibernate.I have searched all the links.But i couldn't find the answer.I was trying to execute the hibernate annotation example i got the error called
**Exception in thread "main" java.lang.AbstractMethodError: ch.qos.logback.classic.Logger.isTraceEnabled()Z .**
Please refer the following details.
Here is my POJO class
package com.vaannila.course; import java.io.Serializable;
import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name="COURSES") public class Course implements Serializable { private long courseId; private String courseName; public Course() { } public Course(String courseName) { this.courseName = courseName; } @Id @GeneratedValue @Column(name="COURSE_ID" ,updatable = false, nullable = false) public long getCourseId() { return this.courseId; } public void setCourseId(long courseId) { this.courseId = courseId; } @Column(name="COURSE_NAME", nullable=false) public String getCourseName() { return this.courseName; } public void setCourseName(String courseName) { this.courseName = courseName; } } ---------------------------------------- Here is my configuration file
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/sample</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.connection.username">sa</property> <property name="connection.password">root</property> <property name="show_sql">true</property> <property name="hbm2ddl.auto">create</property> <mapping class="com.vaannila.course.Course" /> </session-factory> </hibernate-configuration> -------------------------------------------------------------------- here is my util class is
package com.vaannila.util; import org.hibernate.SessionFactory; import org.hibernate.cfg.AnnotationConfiguration; public class HibernateUtil { private static final SessionFactory sessionFactory; static { try { sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory(); } catch (Throwable ex) { System.err.println("Initial SessionFactory creation failed." + ex); throw new ExceptionInInitializerError(ex); } } public static SessionFactory getSessionFactory() { return sessionFactory; } } -------------------------------------------------------- Here is my test class
package com.vaannila.course;
import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.Transaction;
import com.vaannila.util.HibernateUtil;
public class Main { public static void main(String[] args) { Main obj = new Main(); Long courseId1 = obj.saveCourse("Physics"); } public Long saveCourse(String courseName) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction transaction = null; Long courseId = null; try { transaction = session.beginTransaction(); Course course = new Course(); course.setCourseName(courseName); courseId = (Long) session.save(course); transaction.commit(); } catch (HibernateException e) { transaction.rollback(); e.printStackTrace(); } finally { session.close(); } return courseId; } } ---------------------------------------- Jars in class path are
1.hibernate-commons-annotations.jar 2.hibernate-annotations.jar 3.ejb3-persistence.jar 4.hibernate3.jar 5.dom4j-1.6.1.jar 6.logback-classic-0.8.jar 7.logback-classic-0.3.jar 8.logback-core-0.9.6.jar 9.slf4j-api-1.5.8.jar 10.jta-1.1.jar 11.dom4j-1.6.1.jar 12.antlr-2.7.6.jar 13.commons-collections-3.1.jar 14.cglib-2.2.jar 15.asm-1.5.3.jar 16.mysql-connector-java-5.0.4.jar ---------------------------------------- And the stack trace is
Exception in thread "main" java.lang.AbstractMethodError: ch.qos.logback.classic.Logger.isTraceEnabled()Z at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:116) at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:111) at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2119) at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2115) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1339) at com.lara.Manager.main(Manager.java:20)
|