0

I want to define one to many relation between two entities defined as dynamic models. Sample entities are provided below. one Order can have multiple items in it. Association needed to be defined on "ORDER_ID" column.

please have a look at i am using "entity-name" not "name".

#Order Entity

<class entity-name="Order">

    <id name="id"
        type="long"
        column="ID">
        <generator class="sequence"/>
    </id>
    
    <property name="ORDER_ID" type="string"
        column="ORDER_ID" not-null="true" />


</class>

#OrderItems Entity

<class entity-name="OrderItems">

    <id name="id"
        type="long"
        column="ID">
        <generator class="sequence"/>
    </id>
    
    <property name="ORDER_ID" type="string"
        column="ORDER_ID" not-null="true" />
        


</class>
ke2
  • 1
  • 1

1 Answers1

0

Why do you need this to be "dynamic"? If you just create the classes this will be a lot simpler and you will find lots of resources on the web about how to model these mappings with JPA annotations.

Apart from that, the first result on google for "hbm xml one-to-many example" gave a perfect example that shows how to do this: https://mkyong.com/hibernate/hibernate-one-to-many-relationship-example/

Christian Beikov
  • 15,141
  • 2
  • 32
  • 58
  • in my case there are no entities involved . i have to use not . and i have to use dynamic entities. – ke2 Oct 07 '20 at 06:39
  • I posted you a link to an example. Did that not work for you? Apart from that, it's vital to understand "why" you need to do it this way, because there might be better ways to reach the goal. – Christian Beikov Oct 07 '20 at 06:48
  • mentioned link has example for entity mapping which doesnt work in my case. And for why: I am working on one of the legacy application and where i can to minimal changes only. I know there are better approaches available but i cant use them as it will require significant modification and higher management did not want to take these changes. – ke2 Oct 14 '20 at 07:13