0

Can anyone suggest me how to map two tables in hibernate.

    <hibernate-mapping>
   <class name="com.git.medicalapp.Pojo.CategoryPojo" table="CategoryPojo">
      <id name="categoryId" type="int">
        <generator class="native"/>
      </id>
      <property name="categoryName" type="string"/>
      <property name="categoryDescription" type="string"/>
<property name="disease" type="string"/>

   </class>
</hibernate-mapping>


<hibernate-mapping>
   <class name="com.git.myapp.pojo.Disease" table="Disease">
      <id name="diseaseid" type="int">
        <generator class="native"/>
      </id>
      <property name="diseasename" type="string"/>
      <property name="symptomsid" type="int"/>
      <property name="typeofdisease" type="string"/>
      <property name="treatmenttype" type="string"/>
      <property name="fees" type="int">
   </class>
</hibernate-mapping>

how to make disease name in second hbm as foreign key to first hibernate-mapping block.

  • 1
    Possible duplicate of [Hibernate one-to-one mapping with a reference column (XML mapping)](http://stackoverflow.com/questions/14682169/hibernate-one-to-one-mapping-with-a-reference-column-xml-mapping) – Prabhat Jun 24 '16 at 07:18
  • Why aren't you mapping the tables by their primary key ids? Looks like that'd be diseaseid in this case. Also make sure case camelCase/underscore_case/whatever you're using is consistent with your data model, because it looks like you've got some inconsistencies going on there. Also if disease and disease name are the same thing, consider replacing disease in CategoryPojo with diseaseid, to normalize your data model – Bradley D Jun 24 '16 at 07:55

0 Answers0