报如下,异常是因为,在Person对象中.设置的属性类型不一致造成的..
请检查。对应bean中set方法数据类型和hibernate配置文件中定义的类型是否一致。
比如你Person中的属性id 定义的类型为Integer ,而set方法是int id.这样则会发生这样的错误.改成统一的类型即可..
%%%% Error Creating SessionFactory %%%%
org.hibernate.PropertyAccessException: Exception occurred inside getter of pack.java.model.Person.id
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:148)
at org.hibernate.engine.UnsavedValueFactory.getUnsavedIdentifierValue(UnsavedValueFactory.java:44)
at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:44)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:123)
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 pack.java.hibernate.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:30)
at pack.java.test.HibernateDaoDemo.getSession(HibernateDaoDemo.java:30)
at pack.java.test.HibernateDaoDemo.main(HibernateDaoDemo.java:20)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:145)
... 11 more
Caused by: java.lang.NullPointerException
at pack.java.model.Person.getId(Person.java:14)
... 16 more
%%%% Error Creating SessionFactory %%%%
org.hibernate.InvalidMappingException: Could not parse mapping document from resource pack/java/model/Address_one_to_one.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:569)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1587)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
at pack.java.hibernate.HibernateSessionFactory.rebuildSessionFactory(HibernateSessionFactory.java:68)
at pack.java.hibernate.HibernateSessionFactory.getSession(HibernateSessionFactory.java:52)
at pack.java.test.HibernateDaoDemo.getSession(HibernateDaoDemo.java:30)
at pack.java.test.HibernateDaoDemo.main(HibernateDaoDemo.java:20)
Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping pack.java.model.Address
at org.hibernate.cfg.Mappings.addClass(Mappings.java:118)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:145)
at org.hibernate.cfg.Configuration.add(Configuration.java:669)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:504)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:566)
... 9 more