开发者

Convert SQL to HQL?

How can I convert the following SQL query into HQL?

SE开发者_高级运维LECT  count(sa.AID)
     FROM   A  sa 
  , B sal,C  m 
  WHERE sa.AID = sal.AID(+) and   sa.BID = m.BID and sa.AID ='0001' 


You need to transfer each table/column into it's associated Entity/Class in JAVA, then build the query with Hibernate ORM as below.

Suppose - The entity name for the table sa is saEntity, for the table B is bEntity, and for the table C is cEntity. - The class name for the column AID is AidClass, and for the column BID is BidClass

Then the Hibernate ORM query can be written as per the following (I like formating HQL queries inside annotations on multiple lines to make it easier to read & adapt).

@Query( "SELECT COUNT(sa.AidClass) "
      + "FROM saEntity sa, "
      + "     bEntity sal "
      + "     cEntity m"
      + "WHERE sa.AidClass = sal.AidClass"
      + "  AND sa.BidClass = m.BidClass "
      + "  AND sa.AidClass ='0001'")
public List <?> runMyQueryMethod();


Try looking at the answer to this question.

HQL to SQL converter

Or this article may help..

https://forum.hibernate.org/viewtopic.php?t=972441

If you showed some of the mappings I could probably help with the HQL. You could just use

Session.CreateSQLQuery instead??

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜