java - How to specify a field, so that when we query, using Joda LocalDate or LocalDateTime value for the field, it is mapped to same column? -
i have postgres database has table "draft"
containing column set_up_time, saved timestamp:
@column(nullable = false) @type(type = "org.jadira.usertype.dateandtime.joda.persistentlocaldatetime") localdatetime setuptime;
for reasons need keep structure is. expecting database queries searching records, setuptime localdatetime , setuptime localdate
. how can map in way, hibernate queries database both these types setuptime, , returns results accordingly?
the schema using :
"create table draft (dtype varchar(31) not null, id int8 not null, creation_time timestamp not null, cust_ord varchar(1), description varchar(255), amount decimal(12, 2), user varchar(6), txn_time timestamp, text1from varchar(36), text2from varchar(36), text3from varchar(36), primary key (id))"
what can write queries this:
public void finddrafts(localdate targetdate) { final query query = entitymanager.createquery( "from draft setuptime => :beginofday , setuptime < :beginofnextday"); query.setparameter("beginofday", targetdate.todatetimeatstartofday().tolocaldatetime()); query.setparameter("beginofnextday", targetdate.plusdays(1).todatetimeatstartofday().tolocaldatetime()); return query.getresultlist(); }
Comments
Post a Comment