Hi There
I've inherited an application using Hibernate 2.0 on Tomcat and MySQL for a struts-based community based website. Each Community has a Location, and each Location has a set of adjacent Locations and child Locations, like this:
<hibernate-mapping>
...
<class name="com.iwp.persistence.Location" table="LOCATION" >
<set name="adjacentLocations" lazy="true" table="LOCATION_LOCATION" order-by="locationID ASC" >
<key column="locationID" />
<many-to-many class="com.iwp.persistence.Location" column="adjacentLocationID" />
</set>
<list name="childLocations" cascade="all" lazy="true">
<key column="parentID" />
<index column="childIndex" type="long" />
<one-to-many class="com.iwp.persistence.Location" />
</list>
...
I have had to make the associations lazy for performance. There are a lot of locations, so again for performance I am storing them in the ServletContext, loading on server startup using a Struts plugin. The problem is that when doing this the session needs to be kept open while the application is running so that the lazy collections can be populated.
I am not entirely happy with this solution, because it seems to go against the idea of a session representing a users interaction with the database. It seems like a kludge to me.
Does anyone see any any problems associated with doing this? Can anyone suggest a better way to do this? Is there a way to re-associate another session with a lazy collection, because this would solve the problem more elegantly without too much pain.
Thanks in advance for any advice.
Peter Butler
|