aspose file tools*
The moose likes Object Relational Mapping and the fly likes using join query in hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "using join query in hibernate" Watch "using join query in hibernate" New topic
Author

using join query in hibernate

bamini mini
Greenhorn

Joined: May 05, 2004
Posts: 3
hi

i want to get records from two tables by using join query.
but i got the queryexception error.
i can't get the multiple column values from two tables.
how i will write the select query for getting records from two tables.
pl. help me(if possible)

i give the java files below.


public List getSupforProducts(String prdcode)
{
try
{
SessionFactory sf=HibernateEnvironment.getSessionFactory();
Session sess=sf.openSession();
List supplierList=sess.find("select a.id,a.descfrom groupAccountin(,b.msupplier,b.mnumber from supProduct b where a.id=b.supcode");
Transaction tx = sess.beginTransaction();
tx.commit();
sess.close();
}catch(Exception CreateException){
CreateException.printStackTrace();
}
supplierList;
}
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


Your exception is probably because this query is a bit of a mess. I'd try to write the query directly in SQL in whatever DB tool you have. You'll get pointers from the DB as to what's wrong.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
can you show the exception you got ?

btw: SessionFactory is an expensive Object to create ! You should not create it every method call. Instead keep it somewhere and jsut create new Sessions. Check out the hibernate wiki pages for some receomendations.

pascal
bamini mini
Greenhorn

Joined: May 05, 2004
Posts: 3
hi
i cant get multiple column values by using the foll. query.

supplierList=sess.find("select a.id,a.desc,from groupAccount a in(b.msupplier,b.mnumber from supProduct b where a.id=b.supcode)");


when i am using this query in sql directly, i got the answer.
but in session, i cant get the result.

i think i should use the join query or subclass query.

if anybody knows ,give that concept.
when i am using in query method.

i got the following error.

unexpected token in query (i got this error in server)
and iexplore i got the following error


org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)


root cause

java.lang.NullPointerException
org.apache.jsp.findProducts_jsp._jspService(findProducts_jsp.java:70)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using join query in hibernate