运行后抛出异常
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.usertest.dao.impl.CompanyDaoImpl.save(CompanyDaoImpl.java:13)
at test.Many2OneTest.main(Many2OneTest.java:24)
Caused by: org.hibernate.MappingException: An association from the table user refers to an unmapped class: com.usertest.entity.api.ICompany
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1746)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1680)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1390)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1781)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1865)
at com.usertest.util.Toolkits.<clinit>(Toolkits.java:19)
... 2 more
经查验,需要在UserImpl.hbm.xml中修改配置
<many-to-one name="company" column="company_id" class="com.usertest.entity.impl.CompanyImpl">
其中class写绝对路径最保险