log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
%%%% Error Creating SessionFactory %%%%
org.hibernate.MappingException: Cannot use identity column key generation with <union-subclass> mapping for: cn.itcast.hibernate.domain.Skiller
at org.hibernate.persister.entity.UnionSubclassEntityPersister.<init>(UnionSubclassEntityPersister.java:67)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:61)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:231)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1313)
at cn.itcast.hibernate.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:31)
at cn.itcast.hibernate.Many2One.add(Many2One.java:93)
at cn.itcast.hibernate.Many2One.main(Many2One.java:25)
%%%% Error Creating SessionFactory %%%%
org.hibernate.InvalidMappingException: Could not parse mapping document from resource cn/itcast/hibernate/domain/Employee.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:588)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1606)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1574)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1553)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1527)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1447)
at cn.itcast.hibernate.HibernateSessionFactory.rebuildSessionFactory(HibernateSessionFactory.java:69)
at cn.itcast.hibernate.HibernateSessionFactory.getSession(HibernateSessionFactory.java:53)
at cn.itcast.hibernate.Many2One.add(Many2One.java:93)
at cn.itcast.hibernate.Many2One.main(Many2One.java:25)
Caused by: org.hibernate.DuplicateMappingException: Duplicate table mapping skiller
at org.hibernate.cfg.Mappings.addDenormalizedTable(Mappings.java:192)
at org.hibernate.cfg.HbmBinder.bindUnionSubclass(HbmBinder.java:784)
at org.hibernate.cfg.HbmBinder.handleUnionSubclass(HbmBinder.java:2201)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2114)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2038)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:359)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:273)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:144)
at org.hibernate.cfg.Configuration.add(Configuration.java:688)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:523)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:585)
... 9 more
Exception in thread "main" java.lang.NullPointerException
at cn.itcast.hibernate.Many2One.add(Many2One.java:94)
log4j:WARN Please initialize the log4j system properly.
%%%% Error Creating SessionFactory %%%%
org.hibernate.MappingException: Cannot use identity column key generation with <union-subclass> mapping for: cn.itcast.hibernate.domain.Skiller
at org.hibernate.persister.entity.UnionSubclassEntityPersister.<init>(UnionSubclassEntityPersister.java:67)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:61)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:231)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1313)
at cn.itcast.hibernate.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:31)
at cn.itcast.hibernate.Many2One.add(Many2One.java:93)
at cn.itcast.hibernate.Many2One.main(Many2One.java:25)
%%%% Error Creating SessionFactory %%%%
org.hibernate.InvalidMappingException: Could not parse mapping document from resource cn/itcast/hibernate/domain/Employee.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:588)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1606)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1574)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1553)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1527)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1447)
at cn.itcast.hibernate.HibernateSessionFactory.rebuildSessionFactory(HibernateSessionFactory.java:69)
at cn.itcast.hibernate.HibernateSessionFactory.getSession(HibernateSessionFactory.java:53)
at cn.itcast.hibernate.Many2One.add(Many2One.java:93)
at cn.itcast.hibernate.Many2One.main(Many2One.java:25)
Caused by: org.hibernate.DuplicateMappingException: Duplicate table mapping skiller
at org.hibernate.cfg.Mappings.addDenormalizedTable(Mappings.java:192)
at org.hibernate.cfg.HbmBinder.bindUnionSubclass(HbmBinder.java:784)
at org.hibernate.cfg.HbmBinder.handleUnionSubclass(HbmBinder.java:2201)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2114)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2038)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:359)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:273)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:144)
at org.hibernate.cfg.Configuration.add(Configuration.java:688)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:523)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:585)
... 9 more
Exception in thread "main" java.lang.NullPointerException
at cn.itcast.hibernate.Many2One.add(Many2One.java:94)
at cn.itcast.hibernate.Many2One.main(Many2One.java:25)
错误:不能使用identity这种主键生成器策略
原因:该例子一个有三个类,三张表,如果使用identity主键生成器策略,会使主键id值可能相同,在查询时,无法保证值的唯一,即无法正确查询
改正:可以将主键生成器策略改为hilo