-->
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.  [ 5 posts ] 
Author Message
 Post subject: Asynchronous subclass loading.
PostPosted: Mon Feb 20, 2006 8:19 am 
Beginner
Beginner

Joined: Thu Feb 16, 2006 9:53 am
Posts: 24
Hi,

I've chosen a "Table per subclass, using a discriminator" strategy to map inheritance.
Everything works fine but I have one question about the loading of the subclass properties.
Actually the "lazy" attribute of the "subclass" element seems to have no effects on the sql queries generated, no matter the "fecth" mode ("select" or "join").
The subclass is always loaded with the super class.

For example (using the select fetch mode) the two select queries are always executing simulteanously. Even if I access only a property of the super class. (See below)

What I expect is that Hibernate executes the second query only when a subclass property is needed. This seems to me quite logical as far as some "business" code may only use the super-class.

So how can I "desynchronize" those 2 queries please?
Thanks in advance.

Alexis


http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#inheritance-tablepersubclass-discriminator

Hibernate version: 3.1.2

Java Class:
Code:
public class Event implements Serializable, Comparable {

    private Long id;
    private String dataSourceCode;
    private Map privateInfoMap = new HashMap();
   
    // ....
}


Mapping documents:
Code:
<class name="Event" table="EVENT">       
        <id name="id" type="long">
            <column name="ID"/>
            <generator class="hilo"/>
        </id>
        <discriminator type="string">
            <column name="DS_CODE"
                    length="32"
                    not-null="true"
                    index="&prefix;EVENT_IDX0"/>
        </discriminator>

        <!-- ... -->
       
</class>
   
<!-- Subclass -->
<subclass name="Event"
      entity-name="STPFC_ENTRY_SPACE"
      discriminator-value="STPFC_ENTRY_SPACE"
      lazy="true"
      extends="Event">
   <join table="STPFC_ENTRY_TABLE" fetch="select">
       <key column="EVENT_ID"/>
       <dynamic-component name="privateInfoMap">
           <property name="FC_ID" column="FC_ID" type="long"/>
           <property name="foo" column="FOO" type="string"/>
           <property name="toto" column="TOTO" type="string"/>
       </dynamic-component>           
   </join>
</subclass>


The generated SQL (show_sql=true):
Code:
select event0_.ID as ID0_1_, event0_.DS_CODE as DS2_0_1_ from MSP_EVENT event0_ where event0_.ID=?
select event_1_.FC_ID as FC2_2_, event_1_.FOO as FOO2_, event_1_.TOTO as TOTO2_ from MSP_STPFC_ENTRY_TABLE event_1_ where event_1_.EVENT_ID=?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 20, 2006 9:56 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
You can't. You've decreed that an object of the subclass is modelled as a row of the main table and a row of the subclass table, therefore you will always deal with both rows when handling these objects. It wouldn't make sense to do it any other way.

I notice that your subclass and main class have the same name. I suppose that that's a typo?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 21, 2006 7:14 am 
Beginner
Beginner

Joined: Thu Feb 16, 2006 9:53 am
Posts: 24
Ok, I understand what you said. You're right. Thanks Tenwit.

In fact I guess my real question should be:
how can I load "lazily" the <dynamic-component>?


tenwit wrote:
I notice that your subclass and main class have the same name. I suppose that that's a typo?


No, it's not a typo. In fact I have te deal with some legacy code.
One single Event class has a private map, but this map may have different keys according to the context.
In a pure Object Model, this class would have been extended, one subclass per "key config".

Unfortunately I cannot refactor this class whereas I have to persist it, and make profit of polymorphism.

So my choice is to map several times this single Event class using the entity name feature, subclassing a common base to map every "key config".

Sorry if I am not very clear, but I am very interested in your opinion.
Comments and suggestion are welcome.

Alexis


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 21, 2006 5:35 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Yea, legacy code is a bummer.

dyanimc-component (and component) do support the lazy="true" attribute, so that would be the first thing I'd recommend trying. If that doesn't work, I'd recommend making a new class for STPFC_ENTRY_TABLE and using delegation in the Event subclass to expose it to the normal API. But I'm a big fan of delegation, and there are alternatives, so maybe you won't want to try that.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 5:57 am 
Beginner
Beginner

Joined: Thu Feb 16, 2006 9:53 am
Posts: 24
tenwit wrote:
dyanimc-component (and component) do support the lazy="true" attribute


According to the dtd, you're wrong :
http://hibernate.sourceforge.net/hibern ... ng-3.0.dtd

:((

Code:
<!ELEMENT dynamic-component (
   (property|many-to-one|one-to-one|component|dynamic-component|any|map|set|list|bag|array|primitive-array)*
)>
   <!ATTLIST dynamic-component name CDATA #REQUIRED>
   <!ATTLIST dynamic-component access CDATA #IMPLIED>
   <!ATTLIST dynamic-component unique (true|false) "false">
   <!ATTLIST dynamic-component update (true|false) "true">
   <!ATTLIST dynamic-component insert (true|false) "true">
   <!ATTLIST dynamic-component optimistic-lock (true|false) "true">
   <!ATTLIST dynamic-component node CDATA #IMPLIED>


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