使用会话工厂的buildSessionFactory上的java hibernate异常

时间:2013-04-29 13:18:33

标签: hibernate

我在netbeans中创建了一个java应用程序,它读取csv文件并使用hibernate ORM将数据插入SQL DB。 Java应用程序运行正常,并在我从IDE运行应用程序时将记录插入到数据库中。但是如果我将项目编译成JAR文件并在命令提示符下运行它,那么我会收到以下错误。任何帮助都非常感谢,因为我是Java的新手,我无法弄清楚导致问题的原因。

这是会话的代码

    SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
    Session session = sessionFactory.openSession();

这是从命令提示符

运行时获得的异常
     Exception in thread "main" net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
        at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:237)
        at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
        at net.sf.cglib.proxy.Enhancer.createClass(Enhancer.java:317)
        at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:127)
        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.<init>(AbstractEntityTuplizer.java:135)
        at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
        at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:56)
        at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:295)
        at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
        at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
        at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
        at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
        at com.genreproj.uploadpermission.RepPermissionUpload.ReadPermissionFile(RepPermissionUpload.java:108)
        at com.genreproj.uploadpermission.RepPermissionUpload.ProcessPermissionFile(RepPermissionUpload.java:72)
        at com.genreproj.processalluploads.ProcessAllUploads.main(ProcessAllUploads.java:52)
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at net.sf.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:384)
        at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:219)
        ... 17 more
Caused by: java.lang.SecurityException: class "com.genreproj.entity.SalesHistory$$EnhancerByCGLIB$$11666a3b"'s signer information does not match signer information
of other classes in the same package
        at java.lang.ClassLoader.checkCerts(ClassLoader.java:943)
        at java.lang.ClassLoader.preDefineClass(ClassLoader.java:657)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:785)
        ... 23 more

1 个答案:

答案 0 :(得分:0)

我想出了这个问题,我签署了jar文件并从命令提示符执行它,这导致了问题。如果我在没有签名的情况下运行jar文件,它运行正常!