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