It's not a secret anymore!*
The moose likes Object Relational Mapping and the fly likes Join query in HQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Join query in HQL" Watch "Join query in HQL" New topic
Author

Join query in HQL

Shinu Pil
Greenhorn

Joined: Sep 02, 2005
Posts: 9
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

Joined: Jul 14, 2010
Posts: 754

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


[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
Shinu Pil
Greenhorn

Joined: Sep 02, 2005
Posts: 9
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..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Join query in HQL