Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hi All,
The problem I am facing seems to be very basic but I am unable to figure out the cause or the solution.
I fire a select on a View and get a List of null objects in return. The hibernate generated SQL gives me the expected result. What am I missing?
Please find the details below.
Hibernate version:
Hibernate 3.0
Mapping documents:
ViewBodyCourseCareerSubject.hbm.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="sandbox.shardul.testfilters.ViewBodyCourseCareerSubject" table="view_body_course_career_subject" catalog="xxxx">
<composite-id name="id" class="sandbox.shardul.testfilters.ViewBodyCourseCareerSubjectId">
<key-property name="bodyId" type="java.lang.Long">
<column name="body_id" />
</key-property>
<key-property name="courseId" type="java.lang.Long">
<column name="course_id" />
</key-property>
<key-property name="careerId" type="java.lang.Long">
<column name="career_id" />
</key-property>
<key-property name="subjectId" type="java.lang.Long">
<column name="subject_id" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>
hibernate.cfg.xml
<?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">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="connection.username">root</property>
<property name="connection.url">jdbc:mysql://localhost:3306/xxxx</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="myeclipse.connection.profile">sandbox</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="show_sql">true</property>
<mapping resource="sandbox/shardul/testfilters/ViewBodyCourseCareerSubject.hbm.xml" />
</session-factory>
</hibernate-configuration>
Code between sessionFactory.openSession() and session.close():
Criteria criteria = getSession().createCriteria(ViewBodyCourseCareerSubject.class);
List listR = criteria.list();
System.out.println(listR.size());
Full stack trace of any exception that occurs:
No exception is thrown
Name and version of the database you are using:
MySQL 5.0
The generated SQL (show_sql=true):
Hibernate: select viewbodyco0_.body_id as body1_, viewbodyco0_.course_id as course2_, viewbodyco0_.career_id as career3_, viewbodyco0_.subject_id as subject4_ from xxxx.view_body_course_career_subject viewbodyco0_
Debug level Hibernate log excerpt:
-------------EXCERPT-----------------
11:02:34,968 DEBUG [Loader] result row: null
11:02:34,968 DEBUG [Loader] result set row: 9013
11:02:34,968 DEBUG [LongType] returning '163' as column: body1_70_0_
11:02:34,968 DEBUG [LongType] returning '678' as column: course2_70_0_
11:02:34,968 DEBUG [LongType] returning null as column: career3_70_0_
11:02:34,968 DEBUG [Loader] result row: null
11:02:34,968 DEBUG [Loader] result set row: 9014
11:02:34,968 DEBUG [LongType] returning '163' as column: body1_70_0_
11:02:34,968 DEBUG [LongType] returning '678' as column: course2_70_0_
11:02:34,968 DEBUG [LongType] returning null as column: career3_70_0_
11:02:34,968 DEBUG [Loader] result row: null
11:02:34,968 DEBUG [Loader] result set row: 9015
11:02:34,968 DEBUG [LongType] returning '163' as column: body1_70_0_
11:02:34,968 DEBUG [LongType] returning '678' as column: course2_70_0_
11:02:34,968 DEBUG [LongType] returning null as column: career3_70_0_
11:02:34,968 DEBUG [Loader] result row: null
------------------EXCERPT------------------------------
Thanks,
Shardul