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.  [ 3 posts ] 
Author Message
 Post subject: Overriding mapping fetch strategy using criteria
PostPosted: Fri Jul 07, 2006 6:33 am 
Beginner
Beginner

Joined: Thu Jun 30, 2005 5:15 am
Posts: 21
Hi,

Does anyone know how to enable the join fetch strategy in objects that are collections deeper in the tree hierarchy ?

Example: You have a root object A with two references to B and C. B has a collection D and C has a collection E.

Reading the docs this should be as simple as:

// Criteria for the root A object
.setFetchMode("b.d", FetchMode.JOIN)
.setFetchMode("c.e", FetchMode.JOIN)

But this doesn't work.

Another approach would be:

// Criteria for the root A object
.createCriteria("b")
.setFetchMode("d", FetchMode.JOIN)

But, how do you set now the fetch mode for C? The new criteria references B, not its root A.

Any help or comment would be welcome. I'm stuck here.

Thanks in advance,

- Juan


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 07, 2006 9:45 am 
Regular
Regular

Joined: Wed Sep 28, 2005 6:45 pm
Posts: 56
Hi

I am using code like this:
Code:
order = (Torder) session.createCriteria(Torder.class)
            .setFetchMode("tpackageorders", FetchMode.JOIN)
            .setFetchMode("tpackageorders.tpackagetypesent", FetchMode.JOIN)
            .setFetchMode("tpackageorders.tpackagetypesent.tsent", FetchMode.JOIN)
            .setFetchMode("tpackageorders.tpackagetypesent.tsent.tcontact", FetchMode.JOIN)
            .setFetchMode("tpackageorders.tpackagetypesent.tsent.fromContactid", FetchMode.JOIN)
            .setFetchMode("tpackageorders.tpackagetypesent.tsent.tpacktrack", FetchMode.JOIN)


and its working, hope that helps.

Remember to use the names from the classes, not the tablenames :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 10, 2006 5:52 am 
Beginner
Beginner

Joined: Thu Jun 30, 2005 5:15 am
Posts: 21
That seems to be logical way to do it, and it isn't working. It loads the 'plazasSolicitadas' correctly (using a join), but creates new selects for 'personaAsociada.pensiones' and 'conyuge.pensiones'.

The code is:
Code:
        List result = session.createCriteria(Solicitud.class)
         .setFetchMode("plazasSolicitadas", FetchMode.JOIN)
         .setFetchMode("personaAsociada.pensiones", FetchMode.JOIN)
         .setFetchMode("conyuge.pensiones", FetchMode.JOIN)
         .setFirstResult(primeraSolicitud)
         .setMaxResults(numeroSolicitudes)
         .setFetchSize(numeroSolicitudes)
         .list();



And the mappings (just the relevant parts):

Code:
  <class name="imserso.vtei.modelo.Solicitud">
    <many-to-one cascade="all" fetch="join" name="solicitante"/>
    <many-to-one cascade="all" fetch="join" name="conyuge"/>
    <set cascade="all" order-by="numeroOrden" lazy="false" name="plazasSolicitadas">
      <key column="solicitudId"/>
      <one-to-many class="imserso.vtei.modelo.PlazaSolicitada"/>
    </set>
  </class>

  <class discriminator-value="Persona" name="imserso.vtei.modelo.Persona">
    <set cascade="all" lazy="false" name="pensiones">
      <key column="personaId"/>
      <one-to-many class="imserso.vtei.modelo.Pension"/>
    </set>
    <subclass name="imserso.vtei.modelo.Conyuge" discriminator-value="Conyuge"/>
    <subclass name="imserso.vtei.modelo.Solicitante" discriminator-value="Solicitante"/>
  </class>

  <class name="imserso.vtei.modelo.Pension">
    <id access="field" name="id">
      <generator class="native"/>
    </id>
    <many-to-one fetch="join" name="procedencia"/>
    <many-to-one fetch="join" name="clase"/>
    <property name="cuantiaMensual" access="field"/>
  </class>

  <class name="imserso.vtei.modelo.ClasePension">
    <id access="field" name="id">
      <generator class="native"/>
    </id>
    <property name="descripcion" length="50" access="field"/>
    <property name="codigo" length="1" access="field"/>
  </class>

  <class name="imserso.vtei.modelo.ProcedenciaPension">
    <id access="field" name="id">
      <generator class="native"/>
    </id>
    <property name="descripcion" access="field"/>
    <property name="codigo" length="2" access="field"/>
  </class>


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