Hibernate version:3.1
MySQL 5.0.28
Hi I need help with relation mapping
I dont know what to do and I could not find enough examples for my situation. The hibernate documentation seems hard to me right now. So somebody please help me with this.
I have two java classes Sim(parent) and Message(child). The relationship between Sim and Message is One-to-Many and, Many-to-One (Is this what is called Bidirectional?). Until now this is what I was able to do through online references:
In Sim.java
Code:
public List<Message> getMessages() {
return messages;
}
public void setMessages(List<Message> messages) {
this.messages = messages;
}
In Message.javaCode:
public Sim getSim() {
return sim;
}
public void setSim(Sim sim) {
this.sim = sim;
}
I have the HBM files like this:
Sim.hbm.xml:Code:
<bag inverse="true" cascade="delete" lazy="false" name="messages">
<key column="SIM_ID"/>
<one-to-many class="MessageSource"/>
</bag>
Message.hbm.xmlCode:
<property name="simId" column="SIM_ID" />
<many-to-one insert="false" column="SIM_ID" cascade="none" update="false" outer-join="true" name="sim"/>
And I have the tables defined respectively.
My question is how do I implement the bidirectionalily?
I read on different websites that the associations between the objects to be persisted by the developer. How do I do that?
And also, is the implementation until now correct or are there any errors in it?
How do I write the Unit Tests for these classes
Please help.