java - Crud Repository, date comparison -
i have following sql query:
select * wash_history w w.wash_id in (select wash.id wash wash.car_wash_id = 17) , w.time between '2017-07-13' , '2017-07-22'
and want create query inside interface extends crudrepository
. method is
page<washhistory> findwashhistorybytimebetweenorderbytimedesc(date datefrom, date dateto, pageable pageable);
but method returns empty list, think due java date , sql timestamp? if want more details can add them question. class:
public class washhistory implements serializable { private static final long serialversionuid = 1l; @id @generatedvalue(strategy = generationtype.identity) @basic(optional = false) @column(name = "id") private integer id; // @max(value=?) @min(value=?)//if know range of decimal fields consider using these annotations enforce field validation @column(name = "wash_price") private double washprice; @size(max = 2147483647) @column(name = "car_wash_name") private string carwashname; @basic(optional = false) @notnull @column(name = "time") @temporal(temporaltype.timestamp) private date time; @size(max = 2147483647) @column(name = "status") private string status; @column(name = "bonuses") private integer bonuses=0; @joincolumn(name = "wash_id", referencedcolumnname = "id") @manytoone(fetch = fetchtype.lazy) private wash washid;}
and wash class
public class wash implements serializable { private static final long serialversionuid = 1l; @id @generatedvalue(strategy = generationtype.identity) @basic(optional = false) @column(name = "id") private integer id; @size(max = 2147483647) @column(name = "status") private string status; @column(name = "using_bonuses") private boolean usingbonuses=false; @basic(optional = false) @notnull @column(name = "last_status_time") @temporal(temporaltype.timestamp) private date laststatustime; @onetomany(mappedby = "washid", fetch = fetchtype.lazy) private set<washhistory> washhistoryset; @onetoone(mappedby = "washid", fetch = fetchtype.lazy) private washcomment washcommentset; @joincolumn(name = "car_wash_id", referencedcolumnname = "id") @manytoone(fetch = fetchtype.lazy) private carwash carwashid;}
my pageble
public class limitandoffsetpageable extends pagerequest { private int page; private int size; public limitandoffsetpageable(int page, int size){ super(page,size); this.page=page; this.size=size; } @override public int getoffset(){ return this.page; } }
i pass findwashhistorybytimebetweenorderbytimedesc(new limitandoffsetpageable (0,100))
(offset = 0 , limit = 100)
your problem caused using bad naming conventions: entities should following: (removed redundant lines - if want add constraints not null, add them in @column
)
@entity public class washhistory implements serializable { private static final long serialversionuid = 1l; @id @generatedvalue(strategy = generationtype.identity) private integer id; @column(name = "wash_price") private double washprice; @column(name = "car_wash_name") private string carwashname; @column(name = "time") @temporal(temporaltype.timestamp) private date time; private string status; private integer bonuses=0; @joincolumn(name = "wash_id", referencedcolumnname = "id") @manytoone(fetch = fetchtype.lazy) private wash wash; }
now, method be:
page<washhistory> findallbywashididandtimebetween(integer id, date start, date end, pageable pageable)
sort property should put pageable
object.
Comments
Post a Comment