简体   繁体   中英

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

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

<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. 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

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.

You don't have to specify the class of the composite-id in the hbm.xml file; you have to set the name of the property in your PurchasedTestttt class. Eg it has to look like:

Class 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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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