3

Hy guys, I've an Hibernate question for you. I have a class mapped whit this hbm.xml file

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

The ID is one foreign key of another class :B The the structure of A Entity class is:

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

}

While the B entity as this structure: import java.io.Serializable;

public class B implements Serializable{

    private B propA;
    //GETTER AND SETTER
}

When I do a get request on session, using a B type object like a key,

session.get(A, B);

Such the definition into hbm.xml file, I receive this error:

 `TypeMismatchException: Provided id of the wrong type. Expected: class A, got class B

Have you an answer for this problem?

0 Answers0