This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes mutiple tabels join usage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "mutiple tabels join usage" Watch "mutiple tabels join usage" New topic

mutiple tabels join usage

Ar Reddy

Joined: Nov 03, 2008
Posts: 20
Hi There,

String hql = "select a.measureID, a.Name, b.Name,c.Name from tblMeasure a, tblIndicator b, tblContentArea c, tblIndicatorMeasure d, tblContentAreaIndicator e where a.MeasureID = d.MeasureID and d.IndicatorID = b.IndicatorID and d.IndicatorID = e.IndicatorID and e.ContentAreaID = c.ContentAreaID";
org.hibernate.Query query = session.createQuery(hql);
SearchMeasureData searchData = new SearchMeasureData();

this is my HQL , if I run it on the sqlserver the above query is executing . But in program it's throwing an exception that TblMeasure is not mapped.
even though i have mapped TblMeasure.hbm.xml file in config file. Please give me suggessions.

this is config file

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
<session-factory name="">
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class"></property>
<property name="hibernate.connection.password">reddy</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="hibernate.connection.url">jdbc:sqlserver://localhost:1433;DatabaseName=EPHTN2;instanceName=SQLEXPRESS;</property>
<property name="hibernate.connection.username">bhavya</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="">false</property>
<property name="hibernate.show_sql">true</property>
<mapping resource="com/scimetrika/Bean/TblMeasure.hbm.xml"/>
<mapping resource="TblMeasureInfoBean.hbm.xml"/>
<mapping resource="TblMeasureBean.hbm.xml"/>
<mapping resource="TblStatus.hbm.xml"/>
<mapping resource="TblCalculation.hbm.xml"/>
<mapping resource="TblIndicator.hbm.xml"/>
<mapping resource="TblIndicatorMeasure.hbm.xml"/>
<mapping resource="TblContentArea.hbm.xml"/>
<mapping resource="TblContentAreaIndicator.hbm.xml"/>

Ar Reddy

Joined: Nov 03, 2008
Posts: 20
Please give me some reply
Hemant Thard
Ranch Hand

Joined: Dec 23, 2008
Posts: 122

Use class name instead of table name and use class property instead of column name in your HQL query.

Ar Reddy

Joined: Nov 03, 2008
Posts: 20
Thanks for your reply,
I am able to run the query now with modification of a table name hbm.xml file.
After getting result set i am casting to a bean which has 4 attributes and getter and setter method. Please suggest me what to do.

String hql = "select a.measureId as measureNumber, as measureName," +
" as contentAreaName, as indicatorName from" +
" TblMeasureBean a, " +
" TblIndicatorBean b, " +
" TblContentAreaBean c," +
" TblIndicatorMeasureBean d, " +
" TblContentAreaIndicatorBean e " +
" where a.measureId = d.measureId and " +
"d.indicatorId = b.indicatorId and" +
" d.indicatorId = e.indicatorId and" +
" e.contentAreaId = c.contentAreaId";

org.hibernate.Query query = session.createQuery(hql);

//Vector bag = new Vector();
// calculationTable = (TblCalculation) bag.add(list);
List list = query.list();
Iterator i = list.iterator();

{ SearchMeasureBean searchData = (SearchMeasureBean);

// System.out.println("getMeasureId:"+td.getMeasureId());

I am getting this error

Hibernate: select tblmeasure0_.MeasureId as col_0_0_, tblmeasure0_.Name as col_1_0_, tblindicat1_.NAME as col_2_0_, tblcontent2_.NAME as col_3_0_ from EPHTN2.dbo.tblMeasure tblmeasure0_ cross join TBLINDICATOR tblindicat1_ cross join TBLCONTENTAREA tblcontent2_ cross join TBLINDICATORMEASURE tblindicat3_ cross join TBLCONTENTAREAINDICATOR tblcontent4_ where tblmeasure0_.MeasureId=tblindicat3_.MEASUREID and tblindicat3_.INDICATORID=tblindicat1_.INDICATORID and tblindicat3_.INDICATORID=tblcontent4_.INDICATORID and tblcontent4_.CONTENTAREAID=tblcontent2_.CONTENTAREAID
[Ljava.lang.Object; cannot be cast to com.scimetrika.actionhelpers.SearchMeasureBean
flush done
Hemant Thard
Ranch Hand

Joined: Dec 23, 2008
Posts: 122

Please study the stack trace carefully and i am sure you will find the error.


Have you checked out Aspose?
subject: mutiple tabels join usage
It's not a secret anymore!