Solved

convert sql to JPA

Posted on 2012-03-22
3
2,570 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 52

Expert Comment

by:Huseyin KAHRAMAN
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 52

Accepted Solution

by:
Huseyin KAHRAMAN earned 500 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSMS Imprt data from Excel 7 27
denied execute as 13 31
Help with Progress 4gl Rounding Function 6 28
calculate running total 8 16
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

726 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