-->
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.  [ 2 posts ] 
Author Message
 Post subject: Load object completely no lazy loading.
PostPosted: Wed Jul 20, 2005 6:25 am 
Beginner
Beginner

Joined: Wed Apr 13, 2005 12:49 pm
Posts: 34
Hi folks,

In my application I have the following hierarchy.
Code:
Conversation contains :-
         description (String)
         targetHost (String)
         targetPort (String)
         requests (Set)

Request contains :-
        requestLine (String)
        response (Response)
        overflow (Overflow)
        parameters (Set)
        headers (Set)

Response
        statusLine (String)
        overflow (Overflow)
        parameters (Set)
        headers (set)

Overflow
        oveflowStr (String)

So you can see there's potentially four layers of encapsulation here.
When I retrieve a conversation because of lazy loading at the minute,
I have to iterate down through the whole structure to load the object
completely. I've tried setting lazy to 'false' on all the associations but
without any luck.

There's only one point of entry into and out from my database from my
application. Conversations are either fully loaded or fully saved, there
is no iterative loading bits and pieces as needed.

Is there anyway to ensure that the whole conversation from the objects
directly encapsulated in the conversation object (targetHost, targetPort.. )
right down to the overflowStr in the Response objects overflow object are
loaded without creating a huge HQL statement or iterating through the
conversation Hibernate.initialising everything?


Thanks,
Mark.


Top
 Profile  
 
 Post subject: Solution I think.
PostPosted: Wed Jul 20, 2005 8:07 am 
Beginner
Beginner

Joined: Wed Apr 13, 2005 12:49 pm
Posts: 34
Here's the solution I think...

I created the following HQL
Code:
private static final String retrieveDeepConversation ="from com.recorder.http.Conversation as c " +
                                                                        "left join fetch c.messages message " +
                                                                        "left join fetch message.parameters " +
                                                                        "left join fetch message.headers " +
                                                                        "left join fetch message.response res " +
                                                                        "left join fetch res.parameters " +
                                                                        "left join fetch res.headers " +
                                                                        "where c.conversationId=? " ;


and as the Overflow entity is a member of both the
request and response objects,I set the lazy attribute of the Overflow class mapping definition to be false so that it is loaded straight away.


Code:
<class name="com.recorder.http.attribute.Overflow" table="OVERFLOW" lazy="false">


Is there a similar setting for association sets?

Ultimately i was hoping to have a one-to-one association between
the Request and the Response which would allow Requests to have null Responses.
And then have a one-to-one association from Response to Request where the association could not be null.
i.e. Requests could have zero or one responses but
responses had to have request.

The current mapping I have for these associations is as follows...

Code:
<subclass name="com.recorder.http.Request" discriminator-value="R">
         <property name="requestLine"/>
         <many-to-one name="response"
            column="id"
            cascade="save-update,delete"
            unique="true"
            lazy="false"
            not-null="false"/>
      </subclass>
      
      <subclass name="com.recorder.http.Response" discriminator-value="S">
         <property name="statusLine"/>
         <one-to-one name="request" property-ref="response"/>
      </subclass>


This allows for the request to associate with the response but saving the
response object doesn't set the id column to the primary key of the request.

Any ideas? I guess I'm haveing problems because the two classes are
subclasses of the same class and hence operate on the same table.

Thanks,
Mark.


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

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.