Hi folks,
I've a Message object. Two subclasses inherit this object, Request
and response.
I want to have a one-to-one mapping between the Request and the response
so that the response must have a request associated with it but the request
might not yet have a response associated with it.
The following is my attempt at the mapping.
Code:
<hibernate-mapping>
<class name="com.recorder.http.Message" table="MESSAGE" discriminator-value="M">
<id name="id" column="MESSAGE_ID">
<generator class="native"/>
</id>
<discriminator column="type" type="character"/>
<subclass name="com.recorder.http.Request" discriminator-value="R">
<property name="requestLine"/>
<one-to-one name="Response" class="com.recorder.http.Response" constrained="true"/>
</subclass>
<subclass name="com.recorder.http.Response" discriminator-value="S">
<property name="statusLine"/>
<one-to-one name="Request" class="com.recorder.http.Request"/>
</subclass>
</class>
</hibernate-mapping>
The corresponding code for the request looks like
Code:
public class Request extends Message {
private Response res = null;
public void setResponse (Response response) {
this.response = response;
}
public Response getResponse () {
return this.response;
}
:
:
:
}
The mapping is allowed and when I create the message table it alters
it twice adding constraints.
However when I load a request object and attempt to retrieve it's corresponding response object it seems that the request is it's own response object.
I had a read through the lit and it seems to map these one-to-one mappings by giving them both the same id in their corresponding tables.
Which I guess explains why it loads the same Request object twice.
Am I way off base here? I'm quite new to hibernate and my db expertise is as good as my cooking. I am the king of TV dinners.
Any help would be greatly appreciated.
Thanks,
Mark