-->
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.  [ 12 posts ] 
Author Message
 Post subject: many queries generated
PostPosted: Thu Apr 26, 2007 4:26 pm 
Beginner
Beginner

Joined: Wed Jun 14, 2006 9:44 am
Posts: 22
Hibernate version:2.1.7

Name and version of the database you are using:Oracle 9i

Hi all,

I´m doing a simple HQL, but many selects are generated.

The HQL:

Code:
select c from Company


The mapping are:

Code:
    <class name="Company" table="company"
       proxy="Company">
      <id name="id" column="company_id">
         <generator class="assigned"/>
      </id>

        <one-to-one name="companyArchive" class="CompanyArchive"
            constrained="false" outer-join="true"/>

        .
      .

      .
    </class>

    <class name="CompanyArchive" table="company_archive"
       proxy="CompanyArchive">
        <id name="companyId" column="company_id">
           <generator class="foreign">
              <param name="property">company</param>
           </generator>
        </id>      
        <one-to-one constrained="true" outer-join="false" name="company"
            class="Company"/>
    </class>


but I don´t want the companyArchive data, only company data.

Thank you very much!!!!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 26, 2007 4:38 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
If I recall my H2 correctly, the outer-join="true" means eagerly fetch the association. Change that to false.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 26, 2007 5:19 pm 
Newbie

Joined: Thu Feb 03, 2005 9:19 pm
Posts: 11
Location: Bedford, TX
If you set outer-join to false, you change the results. An inner join will return a result set that excludes rows in Company where there is no row in CompanyArchive.

You need to add lazy="true" to your class definition:

Code:
  <class name="Company" table="company"
      proxy="Company" lazy="true">
    <id name="id" column="company_id">
      <generator class="assigned"/>
    </id>

    <one-to-one name="companyArchive" class="CompanyArchive"
        constrained="false" outer-join="true"/>

....

    </class>

http://www.hibernate.org/hib_docs/refer ... tions-lazy

If this helps, please drop me a point :)

Daniel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 26, 2007 8:00 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
See, I didn't remember my H2 correctly! :D

Thanks, Daniel.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 7:56 am 
Beginner
Beginner

Joined: Wed Jun 14, 2006 9:44 am
Posts: 22
Hi, thanks all

But in relation to generate query only for company?
It´s generating select for companyArchive. O don´t need
companyArchive data, only company data.

Sorry Daniel, I didn´t understand the mapping that you post.
In your mapping you have the proxy="Company" and lazy="true".
But these are equivalent:

Code:
(3)   

proxy (optional): Specifies a class or interface to use for lazy initializing proxies.
(4)   

lazy (optional): Setting lazy="true" is a shortcut equalivalent to specifying the name of the class itself as the proxy interface.


thanks!!!!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 12:36 pm 
Newbie

Joined: Fri Apr 20, 2007 3:46 pm
Posts: 15
Hey Hank,

You have to change your one-one-one association. First thing you need to change is set constrained="true". This indicates that Company always has a CompanyArchive. According to documentation if constrained="false" then it will be always eagerly fetched. I also set lazy="no-proxy"

" specifies that the property should be fetched lazily when the instance variable is first accessed"

So only when you call company.getCompanyArchive() will you issue another select.

http://www.hibernate.org/hib_docs/v3/re ... n-onetoone

<class name="Company" table="company"
proxy="Company">
<id name="id" column="company_id">
<generator class="assigned"/>
</id>

<one-to-one name="companyArchive" class="CompanyArchive"
constrained="true" lazy="no-proxy" />

.
.

.
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 1:17 pm 
Beginner
Beginner

Joined: Wed Jun 14, 2006 9:44 am
Posts: 22
Hi,

I´m using hibernate 2.1.7 and the system is in production.
So, the tag proxy on one-to-one is not possible.

I will test the option constrained=true.

thank you very much!!!!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 1:41 pm 
Beginner
Beginner

Joined: Wed Jun 14, 2006 9:44 am
Posts: 22
Hi again,

Other problem is that the company can or cannot have a companyArchive.
So, constrained=true is not worked for my case. :-(

Is there other solution? :-)

thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 1:50 pm 
Newbie

Joined: Fri Apr 20, 2007 3:46 pm
Posts: 15
If you are using hibernate2 then the option you want to use is lazy="true". I am not sure about constrained being set to false. Best way it to try it and test to see what happens


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 2:19 pm 
Beginner
Beginner

Joined: Wed Jun 14, 2006 9:44 am
Posts: 22
Hi bumbalo,

thanks for your attention.

I´m testing with lazy=true. I´m testing here, but...

thank you!

PS.: sorry, I cannot set your post like helpful for me :-)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 2:41 pm 
Beginner
Beginner

Joined: Wed Jun 14, 2006 9:44 am
Posts: 22
Hi all,

I found an URL for this:

http://www.hibernate.org/162.html

thanks all!!!!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 3:11 pm 
Beginner
Beginner

Joined: Wed Jun 14, 2006 9:44 am
Posts: 22
Is there a way to set the tag constrained=true at run time?


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