org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]

使用Hibernate 插入List数据时出现了以下异常:

 1 SLF4J: The requested version 1.6 by your slf4j binding is not compatible with [1.5.5, 1.5.6, 1.5.7, 1.5.8]
 2 SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
 3 log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
 4 log4j:WARN Please initialize the log4j system properly.
 5 log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
 6 org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
 7     at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:110)
 8     at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:135)
 9     at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:80)
10     at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:323)
11 
12     at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:456)
13     at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:131)
14     at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:84)
15     at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:267)
16     at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1341)
17     at com.bdqn.entity.test.Test.setPics(Test.java:315)
18     at com.bdqn.entity.test.Test.setPhones(Test.java:341)
19     at com.bdqn.entity.test.Test.main(Test.java:67)
20 Caused by: java.lang.reflect.InvocationTargetException
21     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
22     at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
23     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
24     at java.lang.reflect.Constructor.newInstance(Unknown Source)
25     at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:107)
26     ... 11 more
27 Caused by: org.hibernate.PropertyNotFoundException: Could not find a getter for phones in class com.bdqn.entity.User
28     at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:306)
29     at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:299)
30     at org.hibernate.mapping.Property.getGetter(Property.java:294)
31     at org.hibernate.tuple.entity.PojoEntityTuplizer.buildPropertyGetter(PojoEntityTuplizer.java:300)
32     at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:141)
33     at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:78)
34     ... 16 more

根据异常信息中的提示:Could not find a getter for phones in class com.bdqn.entity.User

原因:发现是由于实体类中,使用的属性方法的get和set方法名方法名称的问题!属性为phones,而方法是setPhone(),getPhone(),get和set之后的单词与属性不一致

解决方法:删除原先的set和get方法,重新生成即可!

原文地址:https://www.cnblogs.com/TTDJAVA/p/4434465.html