<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="myPackage">
<class name="A" lazy="false" table="A">
<meta attribute="class-description">
Class description
</meta>
<composite-id>
<key-many-to-one name="propA" class="B">
<column name="propA_column" />
</key-many-to-one>
</composite-id>
<property name="propB" column="propB_column" type="string"
access="field" />
</class>
</hibernate-mapping>
ID是另一个类的一个外键:B A Entity类的结构是:
import java.io.Serializable;
public class A implements Serializable{
private static final long serialVersionUID = ...L;
private B propA;
private String propB;
//GETTER AND SETTER METHOD
}
虽然B实体为此结构: import java.io.Serializable;
public class B implements Serializable{
private B propA;
//GETTER AND SETTER
}
当我在会话上执行get请求时,使用类似键的B类型对象
session.get(A, B);
这样定义到hbm.xml文件中,我收到这个错误:
`TypeMismatchException: Provided id of the wrong type. Expected: class A, got class B
你有这个问题的答案吗?