You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ofbiz.apache.org by Anurag Walia <wa...@hotmail.com> on 2010/04/15 08:51:27 UTC

How can i create sql query using delegator?

Hi

i have an entity like
 <entity entity-name="EmplLeave"  
package-name="org.ofbiz.humanres.employment"    title="Employee Leave
Entity">
        <field name="partyId" type="id-ne"/>
        <field name="fromDate" type="date-time"/>
        <field name="thruDate" type="date-time"/>
        <prim-key field="partyId"/>
        <prim-key field="fromDate"/>
    </entity>

i want a sql query like this by delegator
SELECT * from empl_leave where party_Id=10411 and month(from_date)='4' and
year(from_date)='2010' ;(this is runnig on console)
but when i am trying this in java service
GenericValue emplLeave=(GenericValue)delegator.findByAndCache("EmplLeave",
UtilMisc.toMap("month(fromDate)", submitmonth,"year(fromDate)",submityear),
null);
(then exception is coming on server java.lang.ClassCastException:
javolution.util.FastList)
so please help me how to use sql methods in delegator.

Thanks in advance

Regards
Anurag Walia

-- 
View this message in context: http://n4.nabble.com/How-can-i-create-sql-query-using-delegator-tp1858040p1858040.html
Sent from the OFBiz - User mailing list archive at Nabble.com.

Re: How can i create sql query using delegator?

Posted by Scott Gray <sc...@hotwaxmedia.com>.
OFBiz doesn't work like this, look for example usage of the EntityCondition class in the codebase.  Ultimately you'll need to be doing a "greater than month start and less than month end" type of query.

Regards
Scott

HotWax Media
http://www.hotwaxmedia.com

On 15/04/2010, at 9:29 PM, Anurag Walia wrote:

> 
> Thanks for valuable reply
> 
> 
> but unable to find is coming fromDate because it should change into
> from_Date by entitymodel   
> delegator.findByAndCache("EmplLeave", UtilMisc.toMap("month(fromDate)",
> submitmonth,"year(fromDate)",submityear),  null); 
> 
> 
> Regards
> Anurag
> 
> -- 
> View this message in context: http://n4.nabble.com/How-can-i-create-sql-query-using-delegator-tp1858040p1873104.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.


Re: How can i create sql query using delegator?

Posted by Anurag Walia <wa...@hotmail.com>.
Thanks for valuable reply


but unable to find is coming fromDate because it should change into
from_Date by entitymodel   
delegator.findByAndCache("EmplLeave", UtilMisc.toMap("month(fromDate)",
submitmonth,"year(fromDate)",submityear),  null); 


Regards
Anurag

-- 
View this message in context: http://n4.nabble.com/How-can-i-create-sql-query-using-delegator-tp1858040p1873104.html
Sent from the OFBiz - User mailing list archive at Nabble.com.

Re: How can i create sql query using delegator?

Posted by Erwan de FERRIERES <er...@nereide.fr>.
Le 15/04/2010 08:51, Anurag Walia a écrit :
>
> Hi
>
> i have an entity like
>   <entity entity-name="EmplLeave"
> package-name="org.ofbiz.humanres.employment"    title="Employee Leave
> Entity">
>          <field name="partyId" type="id-ne"/>
>          <field name="fromDate" type="date-time"/>
>          <field name="thruDate" type="date-time"/>
>          <prim-key field="partyId"/>
>          <prim-key field="fromDate"/>
>      </entity>
>
> i want a sql query like this by delegator
> SELECT * from empl_leave where party_Id=10411 and month(from_date)='4' and
> year(from_date)='2010' ;(this is runnig on console)
> but when i am trying this in java service
> GenericValue emplLeave=(GenericValue)delegator.findByAndCache("EmplLeave",
> UtilMisc.toMap("month(fromDate)", submitmonth,"year(fromDate)",submityear),
> null);
> (then exception is coming on server java.lang.ClassCastException:
> javolution.util.FastList)
> so please help me how to use sql methods in delegator.
>
> Thanks in advance
>
> Regards
> Anurag Walia
>
findByAndCache will send you a list, and not a GV. So you may use a 
list, and then use getFirst to have the first element of your list.

HTH,

-- 
Erwan de FERRIERES
www.nereide.biz