Mapping hibernate components to a separate table

前端 未结 1 1548
情歌与酒
情歌与酒 2020-12-31 20:52

Is it possible to configure Hibernate to store a component class in a separate table?

Take the following example:


         


        
相关标签:
1条回答
  • 2020-12-31 21:44

    You can use <join> and <component> together, or did I misunderstand your question?

    <class name="test.ClassA">
      <property name="propA"/>
    
      <join table="ClassB">
        <key column="ClassA_id" />
        <component name="componentProp" class="test.ClassB">
          <property name="propB"/>
        </component>
      </join>
    
    </class>
    

    While you (obviously) do need a foreign key, it does not have to be mapped in object model. Details on join are here - provided for completeness only, I know you know where to get them from :-)

    Documentation at the above link does not explicitly say anything about mapping components within joins, but DTD does allow it and I've had it working in 3.1, so I'm pretty sure it still works fine. Don't know how (or whether it's possible) to map this with annotations, though.

    0 讨论(0)
提交回复
热议问题