-->
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.  [ 4 posts ] 
Author Message
 Post subject: Select not all elements of collection
PostPosted: Thu Sep 04, 2003 6:10 am 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
I have 2 classes Organization and CompanyProperty.
from Organization.xbm.xml :
Code:
<bag
      name="properties"
      table="multilanguage_property"
      lazy="false"
      inverse="true"
      cascade="all"
      where="disc like 'comp'"
>
   <key column="ref_id"/>
   <one-to-many
      class="com.clearview.feedback.db.language.property.CompanyProperty"/>
</bag>


When i execute such query:
Code:
<query name="OrgGetSimilarOrgs"><![CDATA[
            from Organization as org, CompanyProperty as prop where prop.refId = org.id and prop.language.id=? and prop.name = ? and prop.value like ?
        ]]></query>


Hibernate executes such sql queries:
Code:
Hibernate: select organiza0_.org_id as org_id0_, companyp1_.prop_id as prop_id1_, organiza0_.client as client0_, companyp1_.lang_id as lang_id1_, companyp1_.name as name1_, companyp1_.value as value1_, companyp1_.description as descript6_1_, companyp1_.ref_id as ref_id1_ from organization organiza0_, multilanguage_property companyp1_ where companyp1_.disc='comp' and ((companyp1_.ref_id=organiza0_.org_id )and(companyp1_.lang_id=? )and(companyp1_.name=? )and(companyp1_.value like ? ))

Hibernate: select multilan0_.prop_id as prop_id__, language1_.lang_id as lang_id0_, language1_.name as name0_, language1_.description as descript3_0_, multilan0_.prop_id as prop_id1_, multilan0_.lang_id as lang_id1_, multilan0_.name as name1_, multilan0_.value as value1_, multilan0_.description as descript6_1_, multilan0_.ref_id as ref_id1_ from multilanguage_property multilan0_ left outer join language language1_ on multilan0_.lang_id=language1_.lang_id where multilan0_.ref_id=? and multilan0_.disc like 'comp'


in Organization class such set method for CompanyProperties

Code:
protected void setProperties(List properties) throws WrongPropertyException {
    this.properties = properties;
    for (int i = 0; i < properties.size(); i++) {
      CompanyProperty multiLanguageProperty =
          (CompanyProperty) properties.get(i);
      log.info("Company id: "+getId()+" CompanyProperty with name: " + multiLanguageProperty.getName() +
          " value: "+multiLanguageProperty.getValue()+" and language: " + multiLanguageProperty.getLanguage());
    }
  }


In db there 2 properies(
Code:
prop_id__  lang_id0_  name0_ descript3_0_  prop_id1_  lang_id1_   name1_  value1_   descript6_1_   ref_id1_     
111         1          en     English         111        1         name    bonas      Bonas           36           
112         2          fr     French          112        2         name    bonas_fr   BonasFR         36           

) for organization but when executes setProperties method i see such output




Code:
Company id: 36 and properties size: 2 MultiLanguageProperty with id 111 name: null value: null and language: null
Company id: 36 and properties size: 2 MultiLanguageProperty with id 112 name: name value: bonas_fr and language: fr


What's it? Why first element is null except its id?[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 6:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Hibernate has not necessarily finished fully initializing an object when it creates the association.

What about if you do the println *after* we return from the find() call. I bet it is initialized *then*!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 6:44 am 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
gavin wrote:
Hibernate has not necessarily finished fully initializing an object when it creates the association.

What about if you do the println *after* we return from the find() call. I bet it is initialized *then*!


The propblem was in my query. It was:
Code:
<query name="OrgGetSimilarOrgs"><![CDATA[
           from Organization as org, CompanyProperty as prop where prop.refId = org.id and prop.language.id=? and prop.name = ? and prop.value like ?
        ]]></query>

Now i wrote it liek this
Code:
<query name="OrgGetSimilarOrgs"><![CDATA[
            select org from Organization as org, CompanyProperty as prop where prop.refId = org.id and prop.language.id=? and prop.name = ? and prop.value like ?
        ]]></query>


Thank's[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 7:00 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Either query should work!


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