关于网友提出的“ Hibernate 单向多对一 的问题”问题疑问,本网通过在网上对“ Hibernate 单向多对一 的问题”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: Hibernate 单向多对一 的问题描述:
Jd 实体类:
private Integer jdid;
private String jdname;
private Qx qx = new Qx();;
(省略get,set方法)
Jd.hbm.xml配置文件:
Qx 实体类:
private Integer qxid;
private String qxname;
(省略get,set方法)
Qx.hbm.xml配置文件:
数据库设计如下
qx表:
qxid int not null (主键,标识列)
qx nchar(10) not null
jd表:
jdid int not null (主键,标识列)
jd nchar(10) not null
qxid int not null (外键)
测试:
public static void main(String[] args){
Session session = HibernateSessionFactory.getSession();
Jd jd = (Jd)session.get(Jd.class, 1);
}
报错:
部分报错代码:
org.hibernate.MappingException: An association from the table jd refers to an unmapped class: Qx
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1134)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1052)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1168)
at SessionFactory.HibernateSessionFactory.
at Test.HibernateTest.main(HibernateTest.java:14)
请高人指教。。。。。。。。感激不尽。。。。。
解决方案1:
先按1楼说的做一下,应该就不会有问题了
解决方案2:先按楼上说的检查下吧
解决方案3:
Jd.hbm.xml,Qx.hbm.xml检查这两个文件加没加到hibernate.cfg.xml里