-->
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.  [ 6 posts ] 
Author Message
 Post subject: Lazy one-to-one, revisited
PostPosted: Fri Jul 16, 2004 5:14 am 
Newbie

Joined: Fri Jul 16, 2004 4:43 am
Posts: 3
Hello all,
Before I get started I should probably mention that I am well aware of
http://www.hibernate.org/162.html, the hibernate manual and I have spent the last two days reading this forum.

As the subject suggests, I am unable to get lazy loading from a one-to-one mapping.
I have two relatively simple clases in a one-to-one relationship with each other. Everything seems to be set up fine:


Now for the details:
    One of the classes (BlobItemPayload) is tagged as lazy and has its own native generator.
    The other class (BlobItem) has a foreign id, linked to the one-to-one relationship between the two classes. The relationship on this end is constrained.

The entire process of creating and reading objects works flawlessly (no abnormal messages in the log) but whenever I call .list and get a list of BlobItem objects, hibernate goes ahead and does a select for each of them in order to retrieve the associated BlobItemPayload.

I am using the following:
    MS SQL Server 2000 database with the latest (SP2) JDBC drivers from Microsoft[/list
    [list]Hibernate 2.1.4
    J2SDK 1.4.1_02

Any ideas/hints would be greatly appreciated.

Best regards,
diz


The actual mapping is as follows:

Code:
<hibernate-mapping>
    <class        name="com.aspectcapital.util.timeseries.hibernate.BlobItemPayload"
        table="BlobData" dynamic-update="false"
        dynamic-insert="false"  select-before-update="false"
        lazy="true">

        <id name="payload_id" column="payload_id" type="long" >
            <generator class="native"> </generator>
        </id>

        <property .../SNIP/...   />

        <one-to-one
            name="payload_info"
            class="com.aspectcapital.util.timeseries.hibernate.BlobItem"
            cascade="none" outer-join="false" constrained="false" />
    </class>
</hibernate-mapping>



Code:
<hibernate-mapping>
    <class  name="com.aspectcapital.util.timeseries.hibernate.BlobItem"
        table="BlobItems"  dynamic-update="false"                           dynamic-insert="false" select-before-update="false" lazy="true" >

        <id name="item_id" column="item_id" type="long">
            <generator class="foreign">
                <param name="property">payload</param>
            </generator>
        </id>

        <property
          ... /SNIP/ ...>

        <one-to-one name="payload" constrained="true" />
    </class>
</hibernate-mapping>
[/list]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 16, 2004 10:14 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hum, not sure but a foreign generated identifier might break the lazy capability.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 16, 2004 10:26 am 
Newbie

Joined: Fri Jul 16, 2004 4:43 am
Posts: 3
Emmanuel,

What do you think I should use instead? I cannot define an ID without a generator (hibernate doesn't allow that).

I have also attempted to use different types of generators, explicitly (increment, hilo, assigned) without any luck.

Did anyone manage to create a lazy a one-to-one similar to mine?

Best regards,
diz


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 16, 2004 10:28 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
If assigned failed, then there is another problem somewhere. You somehow access BlobItemPayload

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 16, 2004 11:32 am 
Newbie

Joined: Fri Jul 16, 2004 4:43 am
Posts: 3
emmanuel wrote:
If assigned failed, then there is another problem somewhere. You somehow access BlobItemPayload


Unfortunatelly, this is not the case. All the queries are genrated by one statement only:
Code:
List  items = session.find("from com....BlobItem as b");


The queries generated look like this:

Code:
Hibernate: select blobitem0_.item_id as item_id, blobitem0_.start_timestamp as start_ti2_, blobitem0_.end_timestamp as end_time3_, blobitem0_.entries as entries from BlobItems blobitem0_
Hibernate: select blobitempa0_.payload_id as payload_id0_, blobitempa0_.timeseries_data as timeseri2_0_ from BlobData blobitempa0_ where blobitempa0_.payload_id=?
Hibernate: select blobitempa0_.payload_id as payload_id0_, blobitempa0_.timeseries_data as timeseri2_0_ from BlobData blobitempa0_ where blobitempa0_.payload_id=?
.... and so on, one for each BlobItem



Since the last message, I have also attempted to use assigned ids for both ends of the relationship (no foreign generator). It didn't make any difference. :-(

Are there any other ways to obtain the lazy loading? I could, of course save the id of one object manually in the other object and handle all loading/saving by hand. But that pretty much defeats the point of using Hibernate.

Regards,
diz


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 19, 2004 9:16 am 
Beginner
Beginner

Joined: Mon Nov 03, 2003 11:48 pm
Posts: 29
Been trying to do the same thing. See the following links:
http://opensource.atlassian.com/project ... se/HB-1093
http://forum.hibernate.org/viewtopic.ph ... highlight=
http://forum.hibernate.org/viewtopic.ph ... highlight=
http://forum.hibernate.org/viewtopic.ph ... highlight=

As you can see, your setup isn't going to work. It looks like we are going to have to drop the foreign generation on the child for something else and then use many-to-one for the mapping. Still playing with test code to try and firgure out another way.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.