File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

i have a Errors in Hibernate Query

 
Mark Kafe
Ranch Hand
Posts: 60
Hibernate Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use Hibernate Query with outer joins but its created errors the query here.......



there errors track here

java.lang.RuntimeException: org.hibernate.hql.ast.QuerySyntaxException: Path expected for join! [select P.peopleId,P.firstName,P.surname,P.position,Ptt.title from com.itcentrix.altcp.People.People as P LEFT OUTER JOIN PplTitle as Ptt]
at com.itcentrix.altcp.common.AbstractDao.handleException(AbstractDao.java:239)
at com.itcentrix.altcp.common.AbstractDao.findByQuery(AbstractDao.java:186)
at com.itcentrix.altcp.common.DSController.main(DSController.java:53)
Caused by: org.hibernate.hql.ast.QuerySyntaxException: Path expected for join! [select P.peopleId,P.firstName,P.surname,P.position,Ptt.title from com.itcentrix.altcp.People.People as P LEFT OUTER JOIN PplTitle as Ptt]
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:31)
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:24)
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:235)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
at com.itcentrix.altcp.common.AbstractDao.findByQuery(AbstractDao.java:183)
... 1 more


 
stanislav bashkirtsev
Ranch Hand
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You try to select only fields without object? Try to use this:
 
Mark Kafe
Ranch Hand
Posts: 60
Hibernate Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
same error if i try this
 
Rahul Babbar
Ranch Hand
Posts: 210
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do your two hbms People and PplTitle have relationships defined?
If you post your hbms, that will be helpful in finding out the problem.
 
Emanuel Kadziela
Ranch Hand
Posts: 187
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HQL cannot translate this query because it does not know how to get from People to PplTitle. In SQL you provide an "ON" clause for your joins, which in HQL must be done via property access. So if your People entity has a "PplTitle title" field, your query would be "... from People as P left outer join P.title as Ptt." You have to tell hibernate how to join the objects.
 
Mark Kafe
Ranch Hand
Posts: 60
Hibernate Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Rahul Babbar ...
Here the HBMs

People


and People Title


 
Mark Kafe
Ranch Hand
Posts: 60
Hibernate Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Emanuel Kadziela

In People tables Fk of people_title tables......and i define it simple in People class and people HBM not define any relations ships.

can we do this with out relationships?

or i define many to one relation ships.........
 
Rahul Babbar
Ranch Hand
Posts: 210
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

There are a few problems with the way things have been done.

1) According to your mappings, PplTitles is the parent table and People is the child table.(because your PplTitle contains a Set of People). You have enabled mapping from PplTitle to People but you also need to have the mapping in People hbm for relationship with PplTitle. This is because the actual foreign key in contained in the People table and (as far as i know) it should have a many to one relationship from People to PeopleTitle.

2) your Query should have been
select P.peopleId, Ptt.titleId from PplTitle as Ptt LEFT OUTER JOIN Ptt.peoples as P
instead of
select P.peopleId,P.firstName,P.surname,P.position,Ptt.title from People as P LEFT OUTER JOIN PplTitle as Ptt

Notice there are two main changes....
first of all, you should give " LEFT OUTER JOIN Ptt.peoples". (The error Path expected was coming because of it)
secondly, the Left Outer Join should be done from the Parent table to the child table(PplTitle to People) and not from Child Table to Parent Table.

I created the small hibernate setup with your configuration(modified hbms and POJOs) and was able to get the correct results by making the below changes.

1) Modifying the query as mentioned above.
2) adding the following in the People hbm
<many-to-one name="titles"
class="PplTitle"
column="Title_ID"
not-null="true"/>
3) Adding the corresponding PplTitle Field named titles in the People Pojo and putting appropriate getter and setter for it.

Everything worked..


PS. I doubt whether PplTitle is the parent table for People but the association mapping that suggests PplTitle contains a Set of People suggests so..
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic