0

In my application am using JPA entity manager to persist data/fetch data.

em.executeQuery("select * from file_calender_mapping where start_date between :start and :end");

em.setParameter("start",startDate)//startDate is an date object

em.setParameter("end",endDate)//endDate is an date object

List fmlist=em.execute();

The proble is just like this,

"select * from file_calender_mapping where start_date between start and end"

when am passing some date as start= "2011-08-03 05:08:00",and end="2011-08-04 06:08:00" then the mysql return one row having the start time ="2011-08-03 05:30:00",its good,But when my application executing such query it dose not returning any row.Actually what i have seen that my application returning value for two different date,but not for same date different time,thats the main problem. One another thing is my "start" field for Table "file_calender_mapping" datatype is "timestamp".

So what i was thinking that ther may be some problem on JPA/Hibernate

1
  • Can you confirm you're using java.util.Date and not java.sql.Date? Could you add the relevant bits of the class file_calender_mapping (is that a real class name?) Commented Aug 11, 2011 at 9:53

2 Answers 2

3

You can try to specify the exact types of parameters as follows:

em.setParameter("start", startDate, TemporalType.TIMESTAMP);
em.setParameter("end",endDate, TemporalType.TIMESTAMP);
Sign up to request clarification or add additional context in comments.

Comments

0

I have the strong feeling that you're confusing EntityManager.createQuery() with EntityManager.createNativeQuery() and you're somehow capturing all the exceptions, which somehow makes you don't receive anything back.

I'm assuming that, because I don't think you have a class named file_calender_mapping.

edit

The documentation will explain it better than I do, but a JPA QL query is transformed to the navite sql of the DB using the mapping, while a native query is send as it's to the DB. Again, I suggest you to read the documentation, it's quite useful.

1 Comment

can you please tell me what is the difference between EntityManager.createQuery() and EntityManager.createNativeQuery()

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.