こんにちは友人私はSessionFactoryを呼び出すときに休止状態のアプリケーションで支柱を作成しましたsessionFactory=new Configuration()。configure()。buildSessionFactory(); セッション=sessionFactory.openSession(); このコードはエラーを生成します私を助けてくださいサンプルコードはここにありますこれは私の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.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/logintest</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">xxxx</property>
<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">
org.hibernate.cache.NoCacheProvider
</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<mapping resource="hibernate.hbm.xml"/>
私のマッピングファイルはここにあります
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="net.model.Contact" table="contacts">
<id name="id" type="int" column="id" >
<generator class="increment"></generator>
</id>
<property name="firstName" column="firstname"></property>
<property name="lastName" column="lastname"></property>
<property name="cellNo" column="cell_no"></property>
<property name="emailId" column="email_id"></property>
<property name="birthDate" column="birthdate"/>
<property name="website" column="website"/>
</class>
</hibernate-mapping>
メインクラスはこちら
public class Testmain {
public static void main(String args[])
{
Session session=null;
try
{
SessionFactory sessionFactory =new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
Contact contact=new Contact();
contact.setFirstName("mohan");
contact.setLastName("raddy");
contact.setEmailId("mm@gmail.com");
contact.setCellNo("4664564564");
contact.setWebsite("www.stackoverflow.com");
session.save(contact);
session.beginTransaction().commit();
System.out.println("done");
}catch(Exception e)
{
System.out.println(e);
}
session.beginTransaction();
List<Contact> contacts = null;
try {
contacts = (List<Contact>)session.createQuery("from Contact").list();
} catch (HibernateException e) {
e.printStackTrace();
session.getTransaction().rollback();
}
session.getTransaction().commit();
for (Contact contact : contacts) {
System.out.println(contact.getFirstName());
System.out.println(contact.getLastName());
System.out.println(contact.getEmailId());
System.out.println(contact.getCellNo());
System.out.println(contact.getWebsite());
}
}}
メインクラスを実行すると次のエラーが表示されます
スレッド「main」の例外java.lang.NoSuchMethodError:org.objectweb.asm.ClassWriter。(Z)V at net.sf.cglib.core.DebuggingClassWriter。(DebuggingClassWriter.java:47)at net.sf.cglib.core .DefaultGeneratorStrategy.getClassWriter(DefaultGeneratorStrategy.java:30)at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:24)at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:117)atnet.sf.cglib.core.KeyFactoryのnet.sf.cglib.core.KeyFactory$ Generator.create(KeyFactory.java:145) create(KeyFactory.java:108)at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)at net.sf.cglib.proxy.Enhancer。(Enhancer.java:69)atorg.hibernate。 proxy.pojo.cglib.CGLIBLazyInitializer。getProxyFactory(CGLIBLazyInitializer.java:117)at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:43)at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:162)at org .hibernate.tuple.entity.AbstractEntityTuplizer。(AbstractEntityTuplizer.java:135)at org.hibernate.tuple.entity.PojoEntityTuplizer。(PojoEntityTuplizer.java:55)at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping。(Entity 56)org.hibernate.tuple.entity.EntityMetamodel。(EntityMetamodel.java:295)at org.hibernate.persister.entity.AbstractEntityPersister。(AbstractEntityPersister.java:434)at org.hibernate.persister.entity.SingleTableEntityPersister。( SingleTableEntityPersister.java:109)org.hibernate.persister.PersisterFactoryにあります。createClassPersister(PersisterFactory.java:55)at org.hibernate.impl.SessionFactoryImpl。(SessionFactoryImpl.java:226)at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)at net.model.Testmain.main( Testmain.java:25)Java結果:1