Hi, I'm trying to do a very simple thing here. I have a main object that has many children. Lists and sets. When I get my main object, i initialize my child objects one by one. All lists come back with 3 objects regardless of how many are actually in the database. The only case thats correct is if there are 0 in the DB, 0 are returned.
Sets in the exact same code work fine. I'm stuck. Anything wrong in my mapping docs?
Hibernate Version
3.2
Mapping documents:
Parent
Code:
<list name="myMessages" inverse="true">
<key>
<column name="TeenFitID" not-null="true" />
</key>
<index column="TeenFitId"/>
<one-to-many class="com.imediainc.teenfit.datalayer.dto.MyMessages" />
</list>
Child
Code:
<class name="com.imediainc.teenfit.datalayer.dto.MyThoughts" table="MyThoughts">
<id name="thoughtId" type="int">
<column name="ThoughtID" />
<generator class="native" />
</id>
<many-to-one name="teenFitUser" class="com.imediainc.teenfit.datalayer.dto.TeenFitUser" fetch="select">
<column name="TeenFitID" not-null="true" />
</many-to-one>
<property name="thoughtDesc" type="text">
<column name="ThoughtDesc" />
</property>
<property name="postDate" type="timestamp">
<column name="PostDate" length="23" />
</property>
</class>
Code between sessionFactory.openSession() and session.close():I have a DAO that retuns the parent object.
Code:
TeenFitUserDAO zTeenFitUserDAO = new TeenFitUserDAO(hsession);
zTFUser = zTeenFitUserDAO.findByHandle(sHandle_p);
log.info("Initializing Profiles - Size: " + zTFUser.getProfiles());
log.info("Initializing AboutMe - Size: " + zTFUser.getAboutMe().size());
//zTFUser.getMyFriends());
log.info("Initializing MyMessages - Size: " + zTFUser.getMyMessages().size());
log.info("Initializing MyThoughts - Size: " + zTFUser.getMyThoughts().size());
Full stack trace of any exception that occurs:No exception occurs. It just returns 2 empty child objects and 1 hydrated child object in the list. In the database theres actually only 1 child object
Name and version of the database you are using:SQL Server 2000
The generated SQL (show_sql=true):Code:
11:20:04,609 INFO [STDOUT] Hibernate: select mythoughts0_.TeenFitID as TeenFitID1_, mythoughts0_.ThoughtID as ThoughtID1_, mythoughts0_.TeenFitId as TeenFitId1_, mythoughts0_.ThoughtID as ThoughtID68_0_, mythoughts0_.TeenFitID as TeenFitID68_0_, mythoughts0_.ThoughtDesc as ThoughtD3_68_0_, mythoughts0_.PostDate as PostDate68_0_ from MyThoughts mythoughts0_ where mythoughts0_.TeenFitID=?
11:20:04,609 INFO [TeenFitBO] Initializing MyThoughts - Size: 3
Debug level Hibernate log excerpt:
<attribute name="ShowSqlEnabled">true</attribute>
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html