Search code examples
xmlhibernatejpaannotationscomposite-id

I have to rewritew composite-id (xml) to JPA


this is my xml mapping. I need to make JPA mapping

    <composite-id>
        <key-property name="systemId" type="integer" column="SYSTEM_ID"/>
        <key-property name="rollingRackId" type="integer" column="ROLLING_RACK_ID"/>
    </composite-id>

    <property name="status" type="integer" column="ROLLING_RACK_STATUS"/>
    <property name="changeTime" type="timestamp" column="CHANGE_TIME" />

</class>


Solution

  • You have to introduce an Id class

    @Entity @IdClass(KeyClass.class)
    public class Entity{
        @Id int systemId;
        @Id int rollingRackId;
    
    }
    
    
    class KeyClass{
        int systemId;
        int rollingRackId;
    }