-->
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: Can I use filtered collection on a proxy object without load
PostPosted: Tue Dec 13, 2011 2:38 pm 
Beginner
Beginner

Joined: Wed Sep 06, 2006 12:08 pm
Posts: 48
Location: Warsaw - Poland - Europe - Milky Way
Hi

I have a typical one to many mapping:

Code:
@Entity
@org.hibernate.annotations.Entity(dynamicUpdate=true, dynamicInsert=true)
public class ContractAll
{
   // ...

   @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="contractAll")
   public List<ContractHistory> getContractHistory()
   {
      return contractHistory;
   }


And I have a piece of code:

Code:
            em.getTransaction().begin();

            final ContractAll contract = em.getReference(ContractAll.class, 2L);
            final Session sess = (Session)em.getDelegate();

            final Date date =
                  (Date)
                  sess
                  .createFilter(contract.getContractHistory(), "select min(this.chValidFrom) where this.chStatus=:chStatus") // DB HIT to ContractAll
                  .setParameter("chStatus", ChStatusEnum.a)
                  .uniqueResult(); // DB HIT to filtered collection

            em.getTransaction().commit();


In my app there are two database hits (see: DB HIT comments in the source code).
Is it possible to avoid the first database hit (loading proxy from database) and have one and only database hit (to load filtered collection)?

As you can see I don't need (my application doesn't need) to load proxy from database (ContractAll entity) :(
Hibernate have everything in the proxy to perform filtered collection database hit and, I suppose, Hibernate could eliminate this (unnecessary for me) database hit.

Any idea how to decrease the number of DB hits in this code?

Take care,
Adam


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.