请帮帮我,我真的需要帮助…我在hibernate中创建了一个复合id。
PurchasedTestId.java
package jp.go.mhlw.vaccine.draft;
import java.io.Serializable;
public class PurchasedTestId implements Serializable {
private static final long serialVersionUID = 1L;
private Long testId;
private Long customerId;
// an easy initializing constructor
public PurchasedTestId(Long testId, Long customerId) {
this.testId = testId;
this.customerId = customerId;
}
// generate setters and getters here
}
这是我的vaccine .hbm.xml文件
<class name="jp.go.mhlw.vaccine.draft.PurchasedTestttt" table="PurchasedTesttt">
<composite-id name="purchasedTestId" class="jp.go.mhlw.vaccine.draft.PurchasedTestId">
<key-property name="testId" >
<column name="testId" ></column>
</key-property>
<key-property name="customerId" column="customerId" />
</composite-id>
<property name="name" column="name" type="string" />
</class>
我使用Ant构建(使用bulld.xml文件)来生成域类和DB模式,在我的情况下只会生成PurchasedTestttt类,我之前已经创建了purchasedtestd类。当我开始运行工具时,它抛出
org.hibernate.MappingException: class jp.go.mhlw.vaccine.draft.PurchasedTestId not found while looking for property: testId
但是在我的vaccine .hbm.xml文件中,我可以按住control键并点击
jp.go.mhlw.vaccine.draft.PurchasedTestId
并立即跳转到具有相同包名称的purchasedtestd .java文件。显然,purchasedtestd类位于我的类路径中。我已经找了2天了,但我不能解决我的问题。请帮我弄清楚是什么。我太累了
您不必在hbm.xml文件中指定composite-id的类;您必须在PurchasedTestttt类中设置属性的名称。例如:
类PurchasedTestttt:public class PurchasedTestttt {
PurchasedTestId purchasedTestId;
public PurchasedTestId getPurchasedTestId() {
return purchasedTestId;
}
public void setPurchasedTestId(PurchasedTestId purchasedTestId) {
this.purchasedTestId = purchasedTestId;
}
....
}
* .hbm.xml:
<class name=”entities.PurchasedTestttt”>
<composite-id name=”purchasedTestId”>
<key-property name=”testId” column=”TEST_ID” />
<key-property name=”customerId” column=”CUSTOMER_ID” />
</composite-id>
...
</class>
用于composite-id的类必须具有与*.hbm.xml中指定的名称相同的属性,这一点很重要,但是Hibernate不需要知道您为此使用的类