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.  [ 1 post ] 
Author Message
 Post subject: fetch="join" ignored
PostPosted: Tue Oct 30, 2007 6:11 am 
Newbie

Joined: Tue Oct 30, 2007 5:41 am
Posts: 2
Hello!

I've got the following relations

Code:
       :T_BM_PRICING: 1---* :T_BM_ACCEPTANCE: 1---* :T_BM_SECTION_GROUP:


Several acceptances per pricing and several section-groups per acceptance.

Classes:

Code:
public class BMPricing
{
  private Long id;
  ...
  private Set acceptances;
  ...
}


Code:
public class BMAcceptance
{
  private Long id;
  ...
  private Set sectionGroups;
  ...
}


Code:
public class BMSectionGroup
{
  private Long id;
  ...
}


Mappings:

Pricing:
Code:
  ...
  <class name="test.hibernate.app.BMPricing" table="T_BM_PRICING" lazy="false">
    <id column="BM_ITEM_ID" name="id" node="@id" type="long" unsaved-value="undefined">
      <generator class="sequence"><param name="sequence">S_BM_ITEM</param></generator>
    </id>
    <set name="acceptances" cascade="all" fetch="select" lazy="false">
      <key column="BM_ITEM_ID_PARENT"></key>
      <one-to-many entity-name="test.hibernate.app.BMAcceptance" />
    </set>
  </class>
  ...


Acceptance:
Code:
  ...
  <class name="test.hibernate.app.BMAcceptance" table="T_BM_ACCEPTANCE" lazy="false">
    <id column="BM_ITEM_ID" name="id" node="@id" type="long" unsaved-value="undefined">
      <generator class="sequence"><param name="sequence">S_BM_ITEM</param></generator>
    </id>
    <many-to-one entity-name="test.hibernate.app.BMPricing" name="pricing"
      lazy="false" fetch="select" column="BM_ITEM_ID_PARENT" >
    </many-to-one>
    <set name="sectionGroups" node="sectionGroups" cascade="all" fetch="join" lazy="false">
      <key column="BM_ITEM_ID_PARENT"></key>
      <one-to-many entity-name="test.hibernate.app.BMSectionGroup" />
    </set>
  </class>
  ...


SectionGroup:
Code:
  ...
  <class name="test.hibernate.app.BMSectionGroup" table="T_BM_SECTION_GROUP" lazy="false">
    <id column="BM_ITEM_ID" name="id" node="@id" type="long" unsaved-value="undefined">
      <generator class="sequence"><param name="sequence">S_BM_ITEM</param></generator>
    </id>
    <many-to-one entity-name="test.hibernate.app.BMAcceptance" name="acceptance"
      fetch="join" lazy="false" column="BM_ITEM_ID_PARENT" >
    </many-to-one>
  </class>
  ...


Configuration:
Code:
  <hibernate-configuration>
    <session-factory>

      <!-- Hibernate properties -->
   
      <!-- Set a default mode for entity representation -->
      <property name="default_entity_mode">pojo</property>

      <!-- Database connection settings -->
      <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
   
      ...
   
      <property name="hibernate.max_fetch_depth">3</property>
      <property name="hibernate.default_batch_fetch_size">16</property>

      <!-- Enable Hibernate's automatic session context management -->
      <property name="current_session_context_class">thread</property>
 
      <!-- Disable the second-level cache  -->
      <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

      <!-- Mapping files -->
      <mapping resource="test/hibernate/app/V_BM_PRICING.hbm.xml" />
      <mapping resource="test/hibernate/app/V_BM_ACCEPTANCE.hbm.xml" />
      <mapping resource="test/hibernate/app/V_BM_SECTION_GROUP.hbm.xml" />

    </session-factory>
 
  </hibernate-configuration>



when I try to fetch the pricings with

Code:
  Object object = mapSession.get(BMPricing.class, bmItemId);


or

Code:
  Criteria criteria = mapSession.createCriteria(BMPricing.class);
  criteria.add(Restrictions.eq("id", bmItemId));
  Object object = criteria.uniqueResult();


Hibernate executes the following three SQL statements

Code:
  select this_.BM_ITEM_ID as BM1_1_0_from T_BM_PRICING this_ where this_.BM_ITEM_ID=?
  select acceptance0_.BM_ITEM_ID_PARENT as BM5_1_, acceptance0_.BM_ITEM_ID as BM1_1_ from T_BM_ACCEPTANCE acceptance0_ where acceptance0_.BM_ITEM_ID_PARENT=?
  select sectiongro0_.BM_ITEM_ID_PARENT as BM5_1_, sectiongro0_.BM_ITEM_ID as BM1_1_ from T_BM_SECTION_GROUP sectiongro0_ where sectiongro0_.BM_ITEM_ID_PARENT in (?, ?, ?)


but what I expect is something like

Code:
  select
      this_.BM_ITEM_ID as BM1_2_1_
    , sectiongro2_.BM_ITEM_ID_PARENT as BM5_3_
    , sectiongro2_.BM_ITEM_ID as BM1_3_
  from
    T_BM_ACCEPTANCE this_
  left outer join T_BM_SECTION_GROUP sectiongro2_ on this_.BM_ITEM_ID=sectiongro2_.BM_ITEM_ID_PARENT
  where this_.BM_ITEM_ID=?


Version: Hibernate 3.2.2


Do I something wrong or is it not possible to use fetch="join" for certain relations only?


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

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.