线程“main”中的异常java.lang.AbstractMethodError:ch.qos.logback.classic.Logger.isTraceEnabled()Z

时间:2012-07-12 12:51:42

标签: hibernate

我是hibernate的新手。我搜索了所有的链接。但我找不到答案。我试图执行hibernate注释示例我得到了一个名为

的错误

Exception in thread "main" java.lang.AbstractMethodError: ch.qos.logback.classic.Logger.isTraceEnabled()Z

请参阅以下详细信息。

这是我的POJO课程

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;
}
}

这是我的配置文件

<?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>

这是我的util类是

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;
}
}

这是我的测试类

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;
}
}

类路径中的jar是

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

堆栈跟踪

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)

0 个答案:

没有答案