这几天学Hibernate,一个由于粗心,在一个也是由于配置复杂,报了不少错误。
现在贴在这里:
1.主配置文件hibernate.cfg.xml只能加载一个包的映射文件。加载多个包会报错,像这样
java.lang.ExceptionInInitializerError
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from resource cn/xyf/c_hbm_config/Employee.hbm.xml
Caused by: org.hibernate.DuplicateMappingException: duplicate import: Employee refers to both cn.xyf.c_hbm_config.Employee and cn.xyf.a_hello.Employee (try using auto-import="false")
不能在同一个主配置文件上导入多个映射文件
<!-- 3.加载所有映射 -->
<mapping resource="cn/xyf/a_hello/Employee.hbm.xml"/>
<mapping resource="cn/xyf/c_hbm_config/Employee.hbm.xml"/> (应删去一个)