-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Using objects from one session in a different session
PostPosted: Wed Sep 29, 2004 4:24 pm 
Newbie

Joined: Wed Sep 22, 2004 2:01 pm
Posts: 9
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>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 29, 2004 7:24 pm 
Beginner
Beginner

Joined: Tue Dec 09, 2003 3:27 pm
Posts: 21
sure why not, have a look at http://www.hibernate.org/168.html


Top
 Profile  
 
 Post subject: Thanks!
PostPosted: Thu Sep 30, 2004 10:17 am 
Newbie

Joined: Wed Sep 22, 2004 2:01 pm
Posts: 9
Perfect! Thank you,
-E


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.