-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: How to write Join quries in hibernate
PostPosted: Sat Dec 29, 2007 4:59 am 
Newbie

Joined: Fri Dec 07, 2007 9:41 am
Posts: 1
Location: UK
Hi,

Would like to check if it is possible to add multiple join conditions using hibernate

InvProSummary.hbm.xml
Stop.hbm.xml

I didn't put many-to-one or one-to-many property link into hibernate hbm files....

I.e. i need to get the following join condition in SQL

"from InvProSummary as inv LEFT JOIN Stop as st " +
"ON inv.custId = st.custId " +
"where inv.custNo=?"

When i run this from SQL editors, it works fine. If i run from hibernate i am getting following error message


2007-12-29 08:40:57,384 [Thread-24] ERROR org.hibernate.hql.PARSER - line 1:87: unexpected token: ON

org.springframework.orm.hibernate3.HibernateQueryException: unexpected token: ON near line 1, column 87 [from com.fil.web.dao.hibernate.InvProSummary as inv LEFT JOIN Stop as st ON inv.custId = st.custId where inv.custNo=?]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ON near line 1, column 87 [from com.fil.web.dao.hibernate.InvProSummary as inv LEFT JOIN Stop as st ON inv.custId = st.custId where inv.custNo=?]
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:640)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:378)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:847)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:843)
at com.fil.web.dao.inv.InvProSummaryDAOImpl.getCustDetailsByCDB(InvProSummaryDAOImpl.java:91)
at com.fil.web.ui.investor.InvesterQueryTab$11.run(InvProSummaryQueryTab.java:270)
at java.lang.Thread.run(Thread.java:534)
Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ON near line 1, column 87 [from com.fil.web.dao.hibernate.InvProSummary as inv LEFT JOIN Stop as st ON inv.custId = st.custId where inv.custNo=?]
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.parse(QueryTranslatorImpl.java:258)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:157)
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 org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:849)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:373)
... 5 more


How should it be done join quries in hibernate?

thanks for the help in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 29, 2007 5:10 am 
Regular
Regular

Joined: Sat Nov 25, 2006 11:37 am
Posts: 72
Hibernate does not support the ON clause. Check the online HQL documentation for that. For join clauses Hibernate relies on the associations defined in the OR Mapping. As you said you have defined the appropriate mapping just omit the ON clause.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.