Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9209301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:48:37+00:00 2026-06-18T00:48:37+00:00

There is a requirement which i should use the jpa native query (because jpa

  • 0

There is a requirement which i should use the jpa native query (because jpa doesn’t support timestampdiff function).

Also i should select same table twice, such as:
I have table: Individual, Task, and etc

The native query i used is: “select emp.name, tsk.name, app.name, from Individual emp, Task tsk, Individual app where …………….”

The expected data i want is: “Tom, task1, Jack”, however the result data is “Jack, task1, Jack” given this native sql query. Which means the app.name overrides emp.name.

If i want to get the correct result i have to use the query like: “select emp.name, tsk.name, (select app.name from Individual app where xx.id=xx.id), from Individual emp, Task tsk, Individual app where …………….”

code for native query (get wrong data):

String nativeSql = "select con.first_name, app.first_name from Individual con, Task tsk,    TimeBlock tb, Timesheet ts, Individual app where con.id=ts.owner_id and tb.timesheet_id=ts.id and tb.task_id=tsk.id and tsk.approver_id=app.id";
Query query = entityManager.createNativeQuery(nativeSql);

code for native query (can get correct data):

String nativeSql = "select con.first_name, (select app.first_name from Individual app where tsk.approver_id=app.id) from Individual con, Task tsk, TimeBlock tb, Timesheet ts, Individual app where con.id=ts.owner_id and tb.timesheet_id=ts.id and tb.task_id=tsk.id and tsk.approver_id=app.id";
Query query = entityManager.createNativeQuery(nativeSql);

code for jpql query:

String jpql = "select con.firstName, app.firstName from Individual con, Task tsk, TimeBlock tb, Timesheet ts, Individual app where con.id=ts.owner.id and tb.timesheet.id=ts.id and tb.task.id=tsk.id and tsk.approver.id=app.id";
Query query = entityManager.createQuery(jpql);

But the interesting is:

  1. I used this native sql query to search from mysql db (using command line, workbench whatever), the result data is the correct one “Tom, task1, Jack”

  2. If i used the jpql for this requirement without timestampdiff feature, the result data is also the correct one.

  3. Just tried the jdbc, if i used the native sql query in jdbc, I can also get the correct data.

It seems some problem for jpa….

So anyone who met this kind of problem before and know the essential of that.

Thanks for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:48:39+00:00Added an answer on June 18, 2026 at 12:48 am

    Got the same problem, just found out that you got to alias the columns to fix the problem.

    This gave me wrong result :

    SELECT i.number, taux5_50.vatAmount, taux19_60.vatAmount
    FROM Invoice i
    LEFT JOIN InvoiceVATLine taux5_50 ON taux5_50.invoice_id=i.id AND taux5_50.rate=5.50
    LEFT JOIN InvoiceVATLine taux19_60 ON taux19_60.invoice_id=i.id AND taux19_60.rate=19.60
    WHERE ...
    

    This gave me correct result :

    SELECT i.number, taux5_50.vatAmount AS taux5_50_vatAmount, taux19_60.vatAmount AS taux19_60_vatAmount
    FROM Invoice i
    LEFT JOIN InvoiceVATLine taux5_50 ON taux5_50.invoice_id=i.id AND taux5_50.rate=5.50
    LEFT JOIN InvoiceVATLine taux19_60 ON taux19_60.invoice_id=i.id AND taux19_60.rate=19.60
    WHERE ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does there exist a micro-framework for use in browser (IE-support is optional) which provides
I have an ASP MVC application which I also use (as a requirement) as
I got the requirement like, In a page there will be 4 panels which
Can anyone please tell me is there any special requirement to use either EXTERN
I have got a requirement where I need to write a HTML/CSS, which should
I've to create plugin or add-on for my official community site. Requirement There should
I need a SQL statement, the requirement is: there is a table, which has
In my app there is requirement that..I have 6 buttons in a nib, when
There is a requirement in Section 508 to code a Skip Navigation at the
There is a requirement to add a watermark to all the pages in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.