简体   繁体   English

查找属性时找不到org.hibernate.MappingException类

[英]org.hibernate.MappingException class not found while looking for property

Please help me,i really need help... I create a composite-id in hibernate.Here are things i have 请帮助我,我真的需要帮助...我在hibernate中创建了一个复合ID。

PurchasedTestId.java 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
}

And here is my vaccin.hbm.xml file 这是我的vaccin.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>

I am using Ant build (using bulld.xml file) to generate Domain class and DB shema,only class PurchasedTestttt will be generated in my case,I've created the class PurchasedTestId before. 我正在使用Ant构建(使用bulld.xml文件)来生成Domain类和DB shema,在我的情况下只会生成类PurchasedTestttt,我之前已经创建了类PurchasedTestId。 Whenever i start to run tools it throws 每当我开始运行工具时,都会抛出

org.hibernate.MappingException: class jp.go.mhlw.vaccine.draft.PurchasedTestId not found while looking for property: testId

But in my vaccin.hbm.xml file i can hold the control key and click on 但是在我的vaccin.hbm.xml文件中,我可以按住控制键并单击

jp.go.mhlw.vaccine.draft.PurchasedTestId

And it immediately jumps to PurchasedTestId.java file with same package name.Obviously the PurchasedTestId class is in my classpath.I've been searching alot for 2 days but i could not solve my problem.Please help me figure out what it is.I am so tired Please help me. 它立即跳转到具有相同包名称的PurchasedTestId.java文件。显然PurchasedTestId类在我的类路径中。我已经搜索了2天了,但我无法解决问题。请帮我弄清楚它是什么。好累,请帮助我。

You don't have to specify the class of the composite-id in the hbm.xml file; 您不必在hbm.xml文件中指定Composite-id的 you have to set the name of the property in your PurchasedTestttt class. 您必须在PurchasedTestttt类中设置属性的名称 Eg it has to look like: 例如,它必须看起来像:

Class PurchasedTestttt: 类PurchasedTestttt:

public class PurchasedTestttt {
    PurchasedTestId purchasedTestId;

    public PurchasedTestId getPurchasedTestId() {
       return purchasedTestId;
    }
    public void setPurchasedTestId(PurchasedTestId purchasedTestId) {
        this.purchasedTestId = purchasedTestId;
    }
    ....
}

*.hbm.xml: *的.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>

It is important that the class you use for the composite-id has properties with the same name as specified in *.hbm.xml, but Hibernate does not need to know the class you used for that. 重要的是,您用于Composite-id的类具有与* .hbm.xml中指定的名称相同的属性,但是Hibernate不需要知道您用于该类的类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM