Comparing dates in jpa -


i trying find results in postgresql database between 2 dates (field described in ddbb timestamp).

i have these 3 records must meet target: 2016-03-04 00:00:00 2016-03-04 14:00:00 2016-03-04 10:56:00

final calendar fechaminima = calendar.getinstance(); 

and set parameters want.

the jpa column defined:

@column(name = "tim_ofrecim") @notnull @temporal(temporaltype.timestamp) @datetimeformat(style = "m-") private date tewslofr.timofrecim; 

with jpa try find them following code:

@namedquery(name = "ofr_query2", query = "select count (*) tewslofr ofr "                 + "where ofr.id.codidprodto =:codidprodto "                 + "and ofr.coduser =:coduser "                 + "and ofr.timofrecim between :timminimo , :timmaximo")  public static long getmethod(final string codproducto,             final string coduser, final calendar fechaminima,             final calendar fechamaxima) {      return entitymanager().createnamedquery("ofr_query2", long.class)             .setparameter("codidprodto", codproducto)             .setparameter("coduser", coduser)             .setparameter("timminimo", fechaminima, temporaltype.timestamp)             .setparameter("timmaximo", fechamaxima, temporaltype.timestamp)             .getsingleresult(); } 

and obtain exception:

caused by: java.lang.illegalargumentexception: parameter value [java.util.gregoriancalendar[time=?,arefieldsset=false,areallfieldsset=true,lenient=true,zone=sun.util.calendar.zoneinfo[id="europe/paris",offset=3600000,dstsavings=3600000,usedaylight=true,transitions=184,lastrule=java.util.simpletimezone[id=europe/paris,offset=3600000,dstsavings=3600000,usedaylight=true,startyear=0,startmode=2,startmonth=2,startday=-1,startdayofweek=1,starttime=3600000,starttimemode=2,endmode=2,endmonth=9,endday=-1,enddayofweek=1,endtime=3600000,endtimemode=2]],firstdayofweek=2,minimaldaysinfirstweek=4,era=1,year=2016,month=2,week_of_year=10,week_of_month=2,day_of_month=1,day_of_year=67,day_of_week=2,day_of_week_in_month=1,am_pm=0,hour=8,hour_of_day=0,minute=0,second=0,millisecond=434,zone_offset=3600000,dst_offset=0]] not matching type [java.util.date]

the stack trace is:

org.springframework.dao.invaliddataaccessapiusageexception: parameter value [java.util.gregoriancalendar[time=?,arefieldsset=false,areallfieldsset=true,lenient=true,zone=sun.util.calendar.zoneinfo[id="europe/paris",offset=3600000,dstsavings=3600000,usedaylight=true,transitions=184,lastrule=java.util.simpletimezone[id=europe/paris,offset=3600000,dstsavings=3600000,usedaylight=true,startyear=0,startmode=2,startmonth=2,startday=-1,startdayofweek=1,starttime=3600000,starttimemode=2,endmode=2,endmonth=9,endday=-1,enddayofweek=1,endtime=3600000,endtimemode=2]],firstdayofweek=2,minimaldaysinfirstweek=4,era=1,year=2016,month=2,week_of_year=10,week_of_month=2,day_of_month=1,day_of_year=67,day_of_week=2,day_of_week_in_month=1,am_pm=0,hour=9,hour_of_day=0,minute=0,second=0,millisecond=170,zone_offset=3600000,dst_offset=0]] not matching type [java.util.date]; nested exception java.lang.illegalargumentexception: parameter value [java.util.gregoriancalendar[time=?,arefieldsset=false,areallfieldsset=true,lenient=true,zone=sun.util.calendar.zoneinfo[id="europe/paris",offset=3600000,dstsavings=3600000,usedaylight=true,transitions=184,lastrule=java.util.simpletimezone[id=europe/paris,offset=3600000,dstsavings=3600000,usedaylight=true,startyear=0,startmode=2,startmonth=2,startday=-1,startdayofweek=1,starttime=3600000,starttimemode=2,endmode=2,endmonth=9,endday=-1,enddayofweek=1,endtime=3600000,endtimemode=2]],firstdayofweek=2,minimaldaysinfirstweek=4,era=1,year=2016,month=2,week_of_year=10,week_of_month=2,day_of_month=1,day_of_year=67,day_of_week=2,day_of_week_in_month=1,am_pm=0,hour=9,hour_of_day=0,minute=0,second=0,millisecond=170,zone_offset=3600000,dst_offset=0]] not matching type [java.util.date] @ org.springframework.orm.jpa.entitymanagerfactoryutils.convertjpaaccessexceptionifpossible(entitymanagerfactoryutils.java:301) @ org.springframework.orm.jpa.aspectj.jpaexceptiontranslatoraspect.ajc$afterthrowing$org_springframework_orm_jpa_aspectj_jpaexceptiontranslatoraspect$1$18a1ac9(jpaexceptiontranslatoraspect.aj:15) @ com.bbva.arq.front.spring.ewsl.ofrecimientos.api.v1.domain.tewslofr.getcuentaofrecimientosagente_aroundbody2(tewslofr.java:49) @ com.bbva.arq.front.spring.ewsl.ofrecimientos.api.v1.domain.tewslofr.getcuentaofrecimientosagente(tewslofr.java:1) @ com.bbva.arq.front.spring.ewsl.ofrecimientos.api.v1.daos.ofrecimientos.impl.ofrecimientosdaoimpl.getmethod(ofrecimientosdaoimpl.java:52)... caused by: java.lang.illegalargumentexception: parameter value [java.util.gregoriancalendar[time=?,arefieldsset=false,areallfieldsset=true,lenient=true,zone=sun.util.calendar.zoneinfo[id="europe/paris",offset=3600000,dstsavings=3600000,usedaylight=true,transitions=184,lastrule=java.util.simpletimezone[id=europe/paris,offset=3600000,dstsavings=3600000,usedaylight=true,startyear=0,startmode=2,startmonth=2,startday=-1,startdayofweek=1,starttime=3600000,starttimemode=2,endmode=2,endmonth=9,endday=-1,enddayofweek=1,endtime=3600000,endtimemode=2]],firstdayofweek=2,minimaldaysinfirstweek=4,era=1,year=2016,month=2,week_of_year=10,week_of_month=2,day_of_month=1,day_of_year=67,day_of_week=2,day_of_week_in_month=1,am_pm=0,hour=9,hour_of_day=0,minute=0,second=0,millisecond=170,zone_offset=3600000,dst_offset=0]] not matching type [java.util.date] @ org.hibernate.ejb.abstractqueryimpl.registerparameterbinding(abstractqueryimpl.java:360) @ org.hibernate.ejb.queryimpl.setparameter(queryimpl.java:414)

if change date instead of timestamp:

public static long getmethod(final string codproducto,             final string coduser, final calendar fechaminima,             final calendar fechamaxima) {      return entitymanager().createnamedquery("ofr_query2", long.class)             .setparameter("codidprodto", codproducto)             .setparameter("coduser", coduser)             .setparameter("timminimo", fechaminima.gettime(), temporaltype.date)             .setparameter("timmaximo", fechamaxima.gettime(), temporaltype.date)             .getsingleresult(); } 

the code returns 0.

any appreciated.

kindest regards

i still don't know why first option not work, have made work option of date. option correct returning 0 because of de codidprodto, not because of dates.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -