问题
I am trying to take data between specific date ranges from mssql db. But returns nothing. I found a solution here on stackoverflow but it is not working.
Here what I have done :
This is the date field from the entity class:
@Basic(optional = false)
@Column(name = "tarih")
@Temporal(TemporalType.TIMESTAMP)
@DateBridge(resolution = Resolution.MILLISECOND)
private Date tarih;
This is how I am trying to take date between specific dates:
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
Calendar cal = Calendar.getInstance();
Calendar cal2 = new GregorianCalendar();
cal2.setTime(new Date(114, 12, 15, 3, 4,4));
System.out.println(dateFormat.format(cal.getTime()));
System.out.println(dateFormat.format(cal2.getTime()));
TermRangeQuery luceneRangeDateQuery = newStringRange("tarih", DateTools.dateToString(cal2.getTime(), DateTools.Resolution.MILLISECOND),
DateTools.dateToString(cal.getTime(), DateTools.Resolution.MILLISECOND), true, true);
org.hibernate.Query fullTextQuery = fullTextSession.createFullTextQuery(luceneRangeDateQuery);
List<Satislar> kayitliSatislar = fullTextQuery.list();
This is db record and it is type is datetime:
This is the output these 2 lines and query sent:
System.out.println(dateFormat.format(cal.getTime()));
System.out.println(dateFormat.format(cal2.getTime()));
来源:https://stackoverflow.com/questions/34474653/date-range-query-with-lucene