I'm trying to lazily load a collection in Hibeate. From what I've read this is the best practice way to do this:
Session session = HibeateUtil.getSessionFactory().openSession();
session.beginTransaction();
Hibeate.initialize(this.truckReviews);
session.getTransaction().commit();
session.close();
retu this.truckReview;
However, when I run this unit test, the assertion fails:
Truck realTruck = Truck.getTruckByID(1);
TruckReview realFakeReview = new TruckReview();
realFakeReview.setTruck(realTruck);
realFakeReview.setUser(IntegrationTestResources.getTestUser());
realFakeReview.setReviewDate(new Date());
realFakeReview.setReviewStars(5);
realFakeReview.setReviewText("fake review");
realFakeReview.save();
assertTrue(realTruck.loadReviews().contains(realFakeReview));
realFakeReview.delete();
Needless to say, I'm a bit confused since other StackOverflow threads say this is the way to do it properly. I feel like I must be missing something very obvious but I'm still new to Hibeate and have no idea what.
Here's the mapping file for this class:
<hibeate-mapping>
<class name="edu.temple.tutrucks.Truck" table="truck" catalog="TUTrucks" optimistic-lock="version">
<id name="id" type="int">
<column name="id" />
<generator class="identity" />
</id>
<property name="truckName" type="string">
<column name="truck_name" not-null="true" />
</property>
<property name="latitude" type="double">
<column name="latitude" precision="22" scale="0" not-null="true" />
</property>
<property name="longitude" type="double">
<column name="longitude" precision="22" scale="0" not-null="true" />
</property>
<property name="openingTime" type="imm_time">
<column name="opening_time" not-null="false"></column>
</property>
<property name="closingTime" type="imm_time">
<column name="closing_time" not-null="false"></column>
</property>
<property name="avatar" type="string">
<column name="avatar"></column>
</property>
<list name="truckReviews" table="truck_review" inverse="true" lazy="true" fetch="select">
<key>
<column name="truck_id" />
</key>
<list-index column="review_stars" />
<one-to-many class="edu.temple.tutrucks.TruckReview" />
</list>
<list name="menus" table="menu" inverse="true" lazy="false" fetch="select">
<key>
<column name="truck_id" />
</key>
<list-index column="id" />
<one-to-many class="edu.temple.tutrucks.Menu" />
</list>
<set name="tags" table="tag_truck_map" inverse="true" lazy="true" fetch="select">
<key>
<column name="truck_id" />
</key>
<many-to-many column="tag_id" class="edu.temple.tutrucks.Tag"></many-to-many>
</set>
</class>
</hibeate-mapping>
Thanks in advance.
