-->
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: Proper Use Of Projection To Add A Subquery DetachedCriteria.
PostPosted: Wed Aug 06, 2008 9:12 am 
Newbie

Joined: Fri Dec 28, 2007 5:05 am
Posts: 2
Hey guys,

I have two detached criterias which generate a main query and a sub-query. The sub-query is included in the main criteria through the use of criteria.add(Subqueries.eq...:


Code:
//Subquerie criteria to retrieve fair value reporting label
      DetachedCriteria infoFiReportingLabelCriteria = DetachedCriteria.forClass(Reference.class);
      infoFiReportingLabelCriteria.add(Restrictions.eq("type", Constants.ICARE_YES_NO));
      infoFiReportingLabelCriteria.add(Restrictions.eq("code", "N"));
      infoFiReportingLabelCriteria.setProjection(Projections.property("value"));


Code:
      //Main query
      DetachedCriteria criteria =  DetachedCriteria.forClass(E2KAccounts.class);   
      criteria.add(Restrictions.eq(Constants.ACCOUNTTYPE, "GEN"));
      criteria.add(Restrictions.ilike(Constants.ACCOUNT_NUMBER, accountNumberPrefix + "%"));
      criteria.add(Restrictions.gt(Constants.INACTIVATION_DATE, currentDate));
      criteria.addOrder(Order.asc(Constants.ACCOUNT_NUMBER));
      criteria.add(Subqueries.eq("infofiReportingLabel", infoFiReportingLabelCriteria));


"infofiReportingLabel" is a Transient property in the E2KAccounts entity class.

"N" is a harcoded value which shouldn't be hardcoded. More on this later.

The generated SQL obtained from this is the following (minus a bunch details for the sake of clarity):

Code:
SELECT   
         this_.ifi060 AS ifi29_1_0_,
       this_.mntbal AS mntbal1_0_
    FROM ticae2kbdr this_
   WHERE this_.typcpt = 'GEN'
     AND LOWER (this_.mnee2k) LIKE 's%'
     AND this_.datinaact > '2008-08-06 00:00:00'
     AND [b]'infofiReportingLabel'[/b] = (SELECT this0__.nomval AS y0_
                FROM ttypbdr this0__
               WHERE this0__.nomtyp = 'ICARE_YES_NO' AND this0__.codval = [b]"N"[/b]  )
ORDER BY this_.mnee2k ASC


Problem 1
As you can see, I am having issues with the Transient property. I need to somehow tell hibernate to generate a query with a column for the transient field and, when retrieving the result set of E2KAccounts objects, to appropriately set the values of that transient property for each object.

Problem 2
Remember the hardcoded "N" value I talked about early? Here it is:

Code:
WHERE this0__.nomtyp = 'ICARE_YES_NO' AND this0__.codval = [b]"N"[/b]


What I actually want is an equality check with a property of the main object we are retrieving:

Code:
WHERE this0__.nomtyp = 'ICARE_YES_NO' AND this0__.codval = [b]this_.ifi060[/b]


Any insight or answers to these problems I am facing? For now I am just using HQL but would rather have some neat and clean detached criterias.

Thanks and Regards,

- Georges


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.