-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: one-to-one mapping on same table between subclasses
PostPosted: Tue Jul 19, 2005 1:05 pm 
Beginner
Beginner

Joined: Wed Apr 13, 2005 12:49 pm
Posts: 34
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.