How can i create sql query using delegator?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How can i create sql query using delegator?

Anurag Walia
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
Reply | Threaded
Open this post in threaded view
|

Re: How can i create sql query using delegator?

Erwan de FERRIERES
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
Reply | Threaded
Open this post in threaded view
|

Re: How can i create sql query using delegator?

Anurag Walia
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
Reply | Threaded
Open this post in threaded view
|

Re: How can i create sql query using delegator?

Scott Gray-2
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.


smime.p7s (3K) Download Attachment