package hibernate.pojo;
import java.io.Serializable;
import lombok.Data;
@Data
public class AccountHousePk implements Serializable{
private static final long serialVersionUID = 3688136466278232728L;
private long account;
private long houseId;
}
package hibernate.pojo;
import java.io.Serializable;
import lombok.Data;
@Data
public class AccountHouse implements Serializable{
private static final long serialVersionUID = -2541258987160905973L;
AccountHousePk id = new AccountHousePk();
}
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="hibernate.pojo">
<class name="AccountHouse" table="account_house">
<composite-id name="id" class="hibernate.pojo.AccountHousePk">
<key-property name="account"></key-property>
<key-property name="houseId" column="house_id"></key-property>
</composite-id>
</class>
</hibernate-mapping>
<mapping resource="hibernate/mapping/accountHouse.hbm.xml" />
所遇到问题为org.hibernate.PropertyNotFoundException: Could not find a getter for d in class hibernate.pojo.AccountHouse 原因是composite-id name="id"配置写错 此配置应为AccountHouse中的AccountHousePk的属性名