-->
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: Temporal collections and lazy-loading
PostPosted: Fri Apr 28, 2006 10:18 am 
Beginner
Beginner

Joined: Mon Aug 15, 2005 10:20 am
Posts: 32
Location: Brazil
I have a class (Cheque) with a temporal collection (situacoes). Most often, I just need to access the most current object in this collection, but the whole collection is fetched when I call it's getCurrentSituacao() method. Is there some way to instruct Hibernate to fetch only the most current object in this temporal collection?

Mapping:
Code:
<hibernate-mapping>
   <class table="cheque" name="Cheque">
      <cache usage="read-write"/>
   
       <id column="id" name="id">
         <generator class="native"/>
       </id>
      <bag name="situacoes"
         inverse="false"
         cascade="all"
         order-by="start_date"
      >
         <cache usage="read-write"/>

         <key column="cheque_id"/>      
         <one-to-many class="Situacao"/>
      </bag>
    </class>

   <typedef name="EstadoUserType" class="EnumUserType">
        <param name="enumClassName">Estado</param>
        <param name="columnType">string</param>
   </typedef>

    <class table="situacoes" name="Situacao">
       <cache usage="read-write" />
            <id column="id" name="id">
         <generator class="native"/>
       </id>

       <property name="startDate"
          type="timestamp"
          column="start_date"
          not-null="true"
       />
       <property name="endDate"
          type="timestamp"
          column="end_date"
          not-null="false"
       />

       <many-to-one
          column="cheque_id"
          unique="true"
          not-null="true"
          name="cheque"
          class="Cheque"
       />
      
      <property name="estado"
         column="estado"
         type="EstadoUserType"
         not-null="true"
      />
      
   </class>
</hibernate-mapping>

Classes:
Code:
public class Cheque {
    private Long id;
    private List<Situacao> situacoes;
   
    public Cheque() {
        situacoes = new LinkedList<Situacao>();
        Situacao situacaoInicial = new SituacaoImpl(this);
        situacoes.add(situacaoInicial);
    }
   
    public Situacao getCurrentSituacao() {
        return situacoes.get(situacoes.size() - 1);
    }
   
    public List<Situacao> getSituacoes() {
        return situacoes;
    }
   
    public void setSituacoes(List<Situacao> situacoes) {
            this.situacoes = situacoes;
    }
   
    public Estado getCurrentEstado() {
        return this.getCurrentSituacao().getEstado();
    }

}

I've ommitted the Situacao and Estado classes for brevity since I think they're not relevant to this problem.

Thanks in advance,
Daniel Serodio


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.