Hi Hibernators.
I would like to know if it's possible to use an object from one hibernate session in a different session. Here is my plan, please let me know if this is impossible, stupid, or a good idea :-)
I have a table called "Tests" and it contains info about a short, fixed number of tests (name, id, description). It is extremely likely that we will be adding new tests, that's why I chose to make it a table of its own. I have a table for TestPerformed objects which serve as a log for every test that is performed. There is a column in that table which, using a many-to-one association, ties it to the type of Test performed.
I was wondering if it would be possible to open a session at the beginning of the web application which would select all the Tests and then close that session, holding the test objects around in a static class variable, accessible to any servlet that imported that class. Instead of having to perform a "find" on the database and retrieving the test, the tests would all already be retrieved. They are guaranteed not to ever be modified according to my business rules. Can I use those objects from the other session in a session opened for saving new TestPerformed objects? I want to pass a Test instance to testPerformedInstance.setTest(myTestObjFromOtherSession) before saving it.
So is this ridiculous? Is it possible? Any help would be most appreciated. Thanks!
-Eric
Hibernate Mapping files:
Test:
Code:
<class name="Test" table="tests">
   
      <meta attribute="class-description">
         Represents a particular test that can be performed.
         
      </meta>
      
      <id name="id" column="test_id" type="long">
         <generator class="sequence">
            <param name="sequence">seq_test</param>
         </generator>
      </id>
      
      <property name="displayName" column="displayname" type="string">
         <meta attribute="field-description">The name of the test, as displayed to a user</meta>
      </property>
      
      
   </class>
------------
And then the mapping for HistoryEvent and PerformedTest:
Code:
<class name="HistoryEvent" table="historyevents">
   
      <meta attribute="class-description">
         Represents an event that is recorded in the user's history log.
         
      </meta>
      
      <id name="id" column="he_id" type="long">
         <generator class="sequence">
            <param name="sequence">seq_he</param>
         </generator>
      </id>
      
      <discriminator column="type"/>
      
      
      <property name="description" type="string">
         <meta attribute="field-description">Description of the event</meta>
      </property>
         
      <subclass name="PerformedTest" discriminator-value="PT">
         
         <meta attribute="class-description">
            Represents the test performed
         </meta>
         
         <many-to-one name="test" column="test_id" class="ccnmtl.brownfield.Test">
            <meta attribute="field-description">The type of test performed</meta>
         </many-to-one>
         
         <property name="x" type="integer">
            <meta attribute="field-description">The X coord at which it was performed</meta>
         </property>
         
         <property name="y" type="integer">
            <meta attribute="field-description">The Y coord at which it was performed</meta>
         </property>
         
      </subclass>
      
   </class>