0

Can anyone suggest me the solution of fetching data on condition of current date which i am passing in dao layer method of type system current date. for e.g I have to fetch data from table "X" which have a column "startdate" of Date type(Mysql) on the basis if that date is greater with the current date passed to the query in java. I have tried with java.util.Date but not working and also my requirement is not to used database specific function like curr() or Now(). I found a relative post but none helped.Is there no alternative apart from using JodaTime. Thanks.

1 Answer 1

1

In your Entity class mark 'startdate' field with

@Column(name = "startdate")
@Temporal(TemporalType.DATE)
private Date startdate;

And create query like this one:

@NamedQuery(name = "Entity.findAfterDate", query = "SELECT e FROM Entity e WHERE e.startdate >= :dateAfter")

In your EntityDAOImpl

public List<Entity> getEntitiesAfterDate(Date date) {
    Query query = openSession().getNamedQuery("Entity.findAfterDate");
    query.setParameter("dateAfter", date);
    return query.list();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.