Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please help me to convert this SQL to hibernate query

 
Pattamuthu Aru
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
select a.msisdn,sum(b.amount) 'amount'
from account a
inner join accrued_Transaction b on a.msisdn = b.msisdn
where a.account_group = 300 and a.opt_in_date is null and b.year <= 2010
AND b.quarter <= 2 AND (b.opted_in is null OR b.opted_in = 1)
GROUP BY b.msisdn, a.msisdn


HQL seems to be not accepting ON class

Thanks in advance
 
Sue Temple
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your sql works correctly, please ensure that you have the mapping classes right

Hql -
 
Pattamuthu Aru
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried the same but it gave me exception

The named query in account


And the exception is



MY actual SQL query which it seems to work with out any error is like this, so if we able to convert this query in HQL, then it will be good
 
Pattamuthu Aru
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any suggestions or help, please.

Bringing to top
 
Pattamuthu Aru
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Atleast someone please help me to convert this SQL query to Hibernate native query


i have just copy pasted this SQL in java but even then it doesnt work says



Please thanks in advance
 
Cj Recto
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no problem in your query, the problem is with your mapping file I had the same problem before when it comes to joining table.
this link solved my problem in mapping files for joined table.

java4s Join

see if it'll work for you.
 
Mahendr Shinde
Ranch Hand
Posts: 38
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try Native SQL Query if your SQL query works
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic