无法实例化默认的tuplizer异常

时间:2019-08-16 18:58:15

标签: java hibernate exception annotations mapping

最近我将休眠状态从3.1更新到4.3,我试图使用注解而不是xml.Xml一切正常,注解抛出了一堆异常。最后我遇到的异常是下面的堆栈请为它提供一些帮助。我非常需要帮助,因为堆栈跟踪没有给我任何要处理的特定区域。 我在用 休眠4.3 javaassist 3.18

我尝试使用javaassist jar,但所有人都建议使用,但那可以帮助我。但是我有疑问,buildSessionFactory不建议使用hibernate 4.5,这是否是罪魁祸首? 如果有帮助的话,只包括我的HibernateUtils

                connProperties.setProperty( "hibernate.connection.datasource", "java:comp/env/" + MASTER_JDBC_RESOURCE_NAME );
                configuration = new Configuration();
                configuration.addProperties(connProperties);
                sessionFactory = configuration.configure().buildSessionFactory();
                Properties hibernateProperties = configuration.getProperties();
                for (Object k : hibernateProperties.keySet()) {
                    System.out.println("Hibernate Key "+k.toString());
                }
                String testCon = hibernateProperties.getProperty("hibernate.test_connections");
                testConnections = StringUtils.stringToBool(testCon);

我的Stacktrace

  
    

org.hibernate.HibernateException:无法实例化默认tuplizer [org.hibernate.tuple.component.PojoComponentTuplizer]         在org.hibernate.tuple.component.ComponentTuplizerFactory.constructTuplizer(ComponentTuplizerFactory.java:101)         在org.hibernate.tuple.component.ComponentTuplizerFactory.constructDefaultTuplizer(ComponentTuplizerFactory.java:122)         在org.hibernate.tuple.component.ComponentMetamodel。(ComponentMetamodel.java:81)         在org.hibernate.mapping.Component.getType(Component.java:180)         在org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:322)         在org.hibernate.mapping.RootClass.validate(RootClass.java:271)         在org.hibernate.cfg.Configuration.validate(Configuration.java:1360)         在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1851)         在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1930)         在wadetech.DB.base.HibernateUtils。(HibernateUtils.java:111)         在wadetech.DB.base.BaseDAO。(BaseDAO.java:43)         在wadetech.DB.DAOS .__ MaintenanceDAO。(__ MaintenanceDAO.java:10)         在com.at.project.utils.runtime.RuntimeModifier.HasExecuted(RuntimeModifier.java:127)         在wadetech.listeners.ModificationScriptStartupListener.contextInitialized(ModificationScriptStartupListener.java:47)         在org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5016)         在org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5528)         在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)         在org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1575)         在org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1565)         在java.util.concurrent.FutureTask.run(FutureTask.java:262)         在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)         在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615)         在java.lang.Thread.run(Thread.java:745)     造成原因:java.lang.reflect.InvocationTargetException         在sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)处         在sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)         在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)         在java.lang.reflect.Constructor.newInstance(Constructor.java:526)         在org.hibernate.tuple.component.ComponentTuplizerFactory.constructTuplizer(ComponentTuplizerFactory.java:98)         ...另外22个     原因:org.hibernate.PropertyNotFoundException:在类java.lang.String中找不到属性字节的设置方法。         在org.hibernate.property.BasicPropertyAccessor.createSetter(BasicPropertyAccessor.java:246)         在org.hibernate.property.BasicPropertyAccessor.getSetter(BasicPropertyAccessor.java:240)         在org.hibernate.mapping.Property.getSetter(Property.java:328)         在org.hibernate.tuple.component.PojoComponentTuplizer.buildSetter(PojoComponentTuplizer.java:159)         在org.hibernate.tuple.component.AbstractComponentTuplizer。(AbstractComponentTuplizer.java:65)         在org.hibernate.tuple.component.PojoComponentTuplizer。(PojoComponentTuplizer.java:59)         ...另外27个

  

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

我用Google搜索了一个解决方案,不幸的是,大多数为他人解决的答案都对我有所帮助。下面提到了几个投票最多的答案:

  1. 使用javaassist.jar,并确保何时使用它与休眠版本兼容的版本。对于休眠4.3.11,javaassist 3.18可以。
  2. 确保为所有属性定义匹配的获取器/设置器。

我的情况与情况2相似,因此如果有人坚持这些错误,并且情况1有所帮助,那么您唯一可以做的就是对实体类与表名和列名进行全面检查和比较。对我来说,我的任务是将映射从XML迁移到注释,任何因迁移而面临问题的人都需要使用相应的.hbm.xml文件进行交叉检查。