Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Join query in HQL

 
Shinu Pil
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

i have two tables abc and device









my mapping file of abc i added


<many-to-one name="device" class="com.model.device" cascade="all" >
<meta attribute="default-value">new Device()</meta>
<column name="deviceId" />
</many-to-one>
My requirement is that when user search for deviceName from the uI it will fetch data first table and corresponding employee id assigned.If it not assigned need to return null value

How written in hibernate....

i written sample query in mysql it will work fine but i donot know how convert thta into HQl
It is the mysql query




i wriiten corresponding hQL as

i got following exception

rg.hibernate.hql.ast.QuerySyntaxException: unexpected token: from near line 1, column 76 [ ]
org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:281)
org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:180)
org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:134)
org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)

please help on this
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead
LEFT JOIN abc
it should be
LEFT JOIN device.abc

This post show how to work with JPQL/HQL: http://uaihebert.com/?p=1274
 
Shinu Pil
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i resolved this pblm by giving
select abc from ABC ABC LEFT JOIN abc.device
right now i getting results when matching records found in both tables ,but if there is no empid is not in abc and records are in device it not displayed.....wht will do in this situation i tried right join also but no chance to get results.Any help really appreciated..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic