Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

convert sql to JPA

Posted on 2012-03-22
3
Medium Priority
?
3,107 Views
Last Modified: 2012-03-22
I had the below sql and it works well in my data admin..
but I am using this as a named query in eclipse JPA.

SQL:
select * from eventTable eT
where eT.logon_timestamp between (SELECT DATEADD(day, -1, GETDATE()))
and (SELECT DATEADD(day, 0, GETDATE()))

JPA:
@NamedQuery(name = "selectLatestLogonValues", query = "select eventTable from eventTable eT \r\nwhere  eT.logon_timestamp between (SELECT DATEADD(day, -1, GETDATE()))\r\nand (SELECT DATEADD(day, 0, GETDATE()))")})

I got the below error...

java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.tree.MethodNode
 \-[METHOD_CALL] MethodNode: '('
    +-[METHOD_NAME] IdentNode: 'DATEADD' {originalText=DATEADD}
    \-[EXPR_LIST] SqlNode: 'exprList'
       +-[IDENT] IdentNode: 'day' {originalText=day}
       +-[UNARY_MINUS] UnaryArithmeticNode: '-'
       |  \-[NUM_INT] LiteralNode: '1'
       \-[METHOD_CALL] MethodNode: '('
          +-[METHOD_NAME] IdentNode: 'GETDATE' {originalText=GETDATE}
          \-[EXPR_LIST] SqlNode: 'exprList'


I think the DATEADD(day, 0, GETDATE())) function is not available in JPA...
if not do we have an alternative to this in JPA...

all I am trying to do is... get the table entries who logged in last 24 hours..
0
Comment
Question by:shragi
  • 2
3 Comments
 
LVL 61

Expert Comment

by:HainKurt
ID: 37753487
what about

@NamedQuery(name = "selectLatestLogonValues", query = "select * from eventTable eT where  eT.logon_timestamp between DATEADD(day, -1, GETDATE()) and DATEADD(day, 0, GETDATE())")
0
 
LVL 61

Accepted Solution

by:
HainKurt earned 2000 total points
ID: 37753502
or simpler form

@NamedQuery(name = "selectLatestLogonValues", query = "select * from eventTable eT where  eT.logon_timestamp between GETDATE()-1 and GETDATE()")
0
 
LVL 7

Expert Comment

by:gudii9
ID: 37754298
Here is interesting explanation, links

Hibernate 3.0 will have a new parser for HQL which will make extending current DB function support feature set and adding arithmetic operations much easier. How much is completed above current support and when cannot currently be discussed since its not in stone as yet. The final is some time off but beta will start soon(ish).


https://forum.hibernate.org/viewtopic.php?f=1&t=931857&sid=890fcf751e8e3b2eecc8986b5b39b6b3

http://www.java2s.com/Questions_And_Answers/JPA/Database/hql.htm
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question