K
K
KirylLapouski2017-11-15 18:46:04
Java
KirylLapouski, 2017-11-15 18:46:04

How to map set in hibernate?

Hello, there are two tables: a ward and a bunk. There can be several beds in a ward, that is, a one-to-many relationship. The program also has two classes, a ward and a bed (there are getters and setters in the code, but I did not insert them here so that the code was clearer).

public class RoomEntity {
    private int id;
    private int roomNumber;
    private Integer numberOfBeds;
    private int idResponsibleDoctor;
    private Set beds;
}

public class OccupiedBedsEntity {
    private int id;
    private Timestamp since;
    private Timestamp to;
    private int id_room;
}

It is not possible to map set here is xml for the ward and beds.
<class name="entity.RoomEntity" table="room" schema="" catalog="medicine">
        <id name="id">
            <column name="id" sql-type="int unsigned" not-null="true"/>
        </id>
        <property name="roomNumber">
            <column name="room_number" sql-type="int unsigned" not-null="true"/>
        </property>
        <property name="numberOfBeds">
            <column name="number_of_beds" sql-type="int unsigned"/>
        </property>
        <property name="idResponsibleDoctor">
            <column name="id_responsible_doctor" sql-type="int unsigned" not-null="true"/>
        </property>
        <set name="beds">
            <key column="id_room"></key>
            <one-to-many class="entity.OccupiedBedsEntity"/>
        </set>
    </class>

//Маппинг для койки
   <id name="id">
        <column name="id" sql-type="int unsigned" not-null="true"/>
    </id>
    <property name="since">
        <column name="since_" sql-type="datetime" not-null="true"/>
    </property>
    <property name="to">
        <column name="to_" sql-type="datetime" not-null="true"/>
    </property>
    <property name="id_room">
        <column name="id_room" sql-type="int unsigned" not-null="true"></column>
    </property>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question