Я создаю простой проект аннотаций гибернации, для которого ниже приведены файлы
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="UserData")
public class SaveMethod {
@Id
@Column(name="U_Id")
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;
@Column(name="U_Name")
private String name;
@Column(name="U_Age")
private int age;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
Тестовый файл для этого:
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
public class TestData {
public static void main(String[] args) {
TestData data = new TestData();
data.Test();
}
public void Test()
{
SessionFactory sess = new
AnnotationConfiguration().configure().buildSessionFactory();
Session session =sess.openSession();
Transaction tr = session.beginTransaction();
SaveMethod saveMethod = new SaveMethod();
saveMethod.setName("Dnyanesh");
saveMethod.setAge(30);
session.save(saveMethod);
tr.commit();
}
}
Файл hibernate.cfg.xml имеет вид
<?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/newdata</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">1234</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping class="SaveMethod"/>
</session-factory>
</hibernate-configuration>
После запуска я получаю следующую ошибку
log4j: ПРЕДУПРЕЖДЕНИЕ Не может быть никаких дополненийнайдено для регистратора (org.hibernate.cfg.annotations.Version). log4j: WARN Пожалуйста, правильно инициализируйте систему log4j. Исключение в потоке "main" java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit (IILjava / lang / String; Ljava / lang / String; [Ljava / lang / String; Ljava / lang / String;) V atnet.sf.cglib.core.ClassEmitter.begin_class (ClassEmitter.java:77) в net.sf.cglib.core.KeyFactory $ Generator.generateClass (KeyFactory.java:173) в net.sf.cglib.core.DefaultGeneratorStrategy. создать (DefaultGeneratorStrategy.java:25) в net.sf.cglib.core.AbstractClassGenerator.create (AbstractClassGenerator.java:216) в net.sf.cglib.core.KeyFactory $ Generator.create (KeyFactory.java:145) в сети.sf.cglib.core.KeyFactory.create (KeyFactory.java:117) в net.sf.cglib.core.KeyFactory.create (KeyFactory.java:108) в net.sf.cglib.core.KeyFactory.create (KeyFactory.java: 104) в net.sf.cglib.proxy.Enhancer. (Enhancer.java:69) в org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory (CGLIBLazyInitializer.java:117) в org.h.pojo.cglib.CGLIBProxyFactory.postInstantiate (CGLIBProxyFactory.java:43) в org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory (PojoEntityTuplizer.java:162) в org.hibernate.tuple.entity.AbstractEntityTuplizer. 55) в org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping. (EntityEntityModeToTuplizerMapping.java:56) в org.hibernate.tuple.entity.EntityMetamodel. (EntityMetamodel.jnters.iber.hister. 29)AbstractEntityPersister.java:434) в org.hibernate.persister.entity.SingleTableEntityPersister. (SingleTableEntityPersister.java:109) в org.hibernate.persister.PersisterFactory.createClassPersister (PersisterFactory.java:lF. (SessionFactoryImpl.java:226) в org.hibernate.cfg.Configuration.buildSessionFactory (Configuration.java:1294) в org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory (AnnotationConfiguration.java:859) в TestData.java: TestData.java: TestData.java (TestData.java: TestData.java: TestData.java: TestData.java (TestData.java: TestData.java: TestData.java: TestData.java: TestData.java: TestData.java: TestData.java: TestData.java: TestData.java: TestData.java: TestData.java: TestData.java: TestData.java: TestData.java: TestData.java: TestData.java: TestData.java: TestData.java: TestData.java: TestData.java: TestData.java: TestData.java: TestData.j11)