2011-05-12 70 views
0

我得到這個錯誤,當我運行我的Java應用程序我Hibernate一起工作:冬眠org.objectweb.asm.classwriter

java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter

,我加入ASM的所有罐子

控制檯:

12 mai 2011 09:57:53 net.sf.hibernate.cfg.Environment <clinit> 
INFO: Hibernate 2.1.6 
12 mai 2011 09:57:53 net.sf.hibernate.cfg.Environment <clinit> 
INFO: hibernate.properties not found 
12 mai 2011 09:57:53 net.sf.hibernate.cfg.Environment <clinit> 
INFO: using CGLIB reflection optimizer 
12 mai 2011 09:57:53 net.sf.hibernate.cfg.Configuration configure 
INFO: configuring from file: hibernate.cfg.xml 
12 mai 2011 09:57:53 net.sf.hibernate.cfg.Configuration addResource 
INFO: Mapping resource: org/projet/Timesheet.hbm.xml 
12 mai 2011 09:57:53 net.sf.hibernate.cfg.Binder bindRootClass 
INFO: Mapping class: org.projet.Timesheet -> timesheet 
12 mai 2011 09:57:53 net.sf.hibernate.cfg.Configuration doConfigure 
INFO: Configured SessionFactory: null 
12 mai 2011 09:57:53 net.sf.hibernate.cfg.Configuration secondPassCompile 
INFO: processing one-to-many association mappings 
12 mai 2011 09:57:53 net.sf.hibernate.cfg.Configuration secondPassCompile 
INFO: processing one-to-one association property references 
12 mai 2011 09:57:53 net.sf.hibernate.cfg.Configuration secondPassCompile 
INFO: processing foreign key constraints 
12 mai 2011 09:57:53 net.sf.hibernate.dialect.Dialect <init> 
INFO: Using dialect: net.sf.hibernate.dialect.MySQLDialect 
12 mai 2011 09:57:53 net.sf.hibernate.cfg.SettingsFactory buildSettings 
INFO: Maximim outer join fetch depth: 2 
12 mai 2011 09:57:53 net.sf.hibernate.cfg.SettingsFactory buildSettings 
INFO: Use outer join fetching: true 
12 mai 2011 09:57:53 net.sf.hibernate.connection.DriverManagerConnectionProvider configure 
INFO: Using Hibernate built-in connection pool (not for production use!) 
12 mai 2011 09:57:53 net.sf.hibernate.connection.DriverManagerConnectionProvider configure 
INFO: Hibernate connection pool size: 20 
12 mai 2011 09:57:53 net.sf.hibernate.connection.DriverManagerConnectionProvider configure 
INFO: using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://localhost:3306/timesheet 
12 mai 2011 09:57:53 net.sf.hibernate.connection.DriverManagerConnectionProvider configure 
INFO: connection properties: {user=root, password=manel} 
12 mai 2011 09:57:53 net.sf.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory 
INFO: Transaction strategy: net.sf.hibernate.transaction.JDBCTransactionFactory 
12 mai 2011 09:57:53 net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup 
INFO: No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended) 
12 mai 2011 09:57:53 net.sf.hibernate.cfg.SettingsFactory buildSettings 
INFO: Use scrollable result sets: true 
12 mai 2011 09:57:53 net.sf.hibernate.cfg.SettingsFactory buildSettings 
INFO: Use JDBC3 getGeneratedKeys(): true 
12 mai 2011 09:57:53 net.sf.hibernate.cfg.SettingsFactory buildSettings 
INFO: Optimize cache for minimal puts: false 
12 mai 2011 09:57:53 net.sf.hibernate.cfg.SettingsFactory buildSettings 
INFO: Query language substitutions: {} 
12 mai 2011 09:57:53 net.sf.hibernate.cfg.SettingsFactory buildSettings 
INFO: cache provider: net.sf.hibernate.cache.EhCacheProvider 
12 mai 2011 09:57:53 net.sf.hibernate.cfg.Configuration configureCaches 
INFO: instantiating and configuring caches 
Exception in thread "main" java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(Z)V 
    at net.sf.cglib.core.DebuggingClassWriter.<init>(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:215) 
    at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:145) 
    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:117) 
    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108) 
    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104) 
    at net.sf.hibernate.impl.SessionFactoryImpl.<clinit>(SessionFactoryImpl.java:236) 
    at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:791) 
    at org.projet.ModelTime.configure(ModelTime.java:28) 
    at org.projet.TestClient.main(TestClient.java:19) 
+1

您添加了哪個版本的ASM? – skaffman 2011-05-12 09:23:24

回答

1

當提供的庫版本沒有所需的類時會發生這種情況。雖然沒有一般的解決方法,但是您可以嘗試使用這種適合我的方法。

您只需要從休眠中正確排除ASM庫並單獨包含它。看起來很模糊,但看看工作pom.xml中的片段。這種方法背後的意圖是包含項目中某些其他第三庫可能需要的更高版本的相關庫。

包括hibernate實體管理器我正在使用以下代碼。

<dependency> 
    <groupId>org.hibernate</groupId> 
    <artifactId>hibernate-entitymanager</artifactId> 
    <version>${hibernate.version}</version> 
    <exclusions> 
     <exclusion> 
     <groupId>asm</groupId> 
     <artifactId>asm</artifactId> 
     </exclusion> 
     </exclusions> 
    </dependency> 

在這裏,我明確地排除從休眠實體列入經理ASM和它旁邊,我分別包括它

<dependency> 
     <groupId>asm</groupId> 
     <artifactId>asm</artifactId> 
     <version>${asm.version}</version> 
    </dependency> 

和性能。這些版本選擇適用於最新項目中的我。

<properties> 
      <hibernate.version>3.6.0.Final</hibernate.version> 
      <asm.version>3.3</asm.version> 
    </properties> 

希望,這可以解決您的問題。

+0

這隻適用於maven項目,這是op沒有說他使用的項目。 – 2011-11-28 17:25:00