| Author |
mutiple tabels join usage
|
Ar Reddy
Greenhorn
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);
session.getTransaction();
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"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="">
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</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="hibernate.search.autoregister_listeners">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"/>
</session-factory>
</hibernate-configuration>
|
 |
Ar Reddy
Greenhorn
Joined: Nov 03, 2008
Posts: 20
|
|
|
Please give me some reply
|
 |
Hemant Thard
Ranch Hand
Joined: Dec 23, 2008
Posts: 119
|
|
Hi,
Use class name instead of table name and use class property instead of column name in your HQL query.
Regards,
Hemant
|
 |
Ar Reddy
Greenhorn
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, a.name as measureName," +
" b.name as contentAreaName, c.name 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);
System.out.println(query.getQueryString());
session.getTransaction();
//Vector bag = new Vector();
// calculationTable = (TblCalculation) bag.add(list);
List list = query.list();
System.out.println(list.size());
Iterator i = list.iterator();
while(i.hasNext())
{ SearchMeasureBean searchData = (SearchMeasureBean)i.next();
// System.out.println("getMeasureId:"+td.getMeasureId());
System.out.println("getMeasureName:-"+searchData.getContentAreaName());
}
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
322
[Ljava.lang.Object; cannot be cast to com.scimetrika.actionhelpers.SearchMeasureBean
flush done
|
 |
Hemant Thard
Ranch Hand
Joined: Dec 23, 2008
Posts: 119
|
|
hi,
Please study the stack trace carefully and i am sure you will find the error.
Regards,
Hemant
|
 |
 |
|
|
subject: mutiple tabels join usage
|
|
|