views:

56

answers:

2

I have 2 table one table is City Table ( int id, string name) and my another table is Distance table(int id,int cityId (FK city),int neighbourId(FK city)),and i want to use hibernate but i cant establish relationships of these table to Hibernate. Thanks for everything...

A: 

what about something like

<class name="City" table="CITIES">
    <id name="id" type="integer">
      <generator class="native" />
    </id>
    <property name="name" />
    <set name="neighbours" table="DISTANCES">      
        <key column="city_id" />
        <many-to-one name="neighbour" class="City" />
    </set>
</class>

didn't test it though.

msparer
A: 

Ok, I can see any problem to do it normally.

<class name="City" table="CITY">
    <id name="id" type="integer">
      <generator class="native" />
    </id>
    <property name="name" />
</class>
<class name="Distance" table="DISTANCE">
    <id name="id" type="integer">
      <generator class="native" />
    </id>
    <many-to-one name="city" column="cityId" class="City"/>
    <many-to-one name="neighbour" column="neighbourId" class="City"/>
</class>

didn't test it neither.

pedromarce