-->
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 states in Hibernate POJO's
PostPosted: Sun Aug 07, 2005 10:29 am 
Newbie

Joined: Mon Mar 07, 2005 9:51 am
Posts: 3
Hibernate version: 3.0.5

Mapping documents: Are certainly ok, so not included

Code between sessionFactory.openSession() and session.close(): the question is about this, so please read on

Name and version of the database you are using: MySQL 4.1

Browser: Firefox 1.0.6, Internet Explorer 6.0.1

Well, I'm trying to combine Hibernate with JSF and I have done the following:

1) In my mapping documents, I'm using the meta-attribute "generated-class" so that I could include own business logic in the class:

Code:
      
<meta attribute="generated-class">package..AbstractFooClass</meta>


In the class itself, I'm currently (and that's where things go wrong) using a state like isSelected (set by the Presentation Framework in a HttpSession). Each time I submit something in my browser, I request the business objects from the HibernateSession (using the HibernateUtil class from the CaveAtEmptor project) and since sometimes the thread changes, the HibernateSession changes too. Thus, other business objects are retrieved from the HibernateSession, which means these have not set the desired state as I submitted it before. This also happens when I close the session of course, as I should do.

I am most certainly doing something seriously wrong, but I've been struggling with this for months now (no joking :s) and still haven't found a decent way to do it.

So a little recap, I need to put some application state in my business (I know, sounds wrong, but no idea of how to do it otherwise) objects that is not saved in the database, but I don't want to keep a session open as long as the HttpSession is still valid.

As far as I know, I should be doing the following (according to most documentation and tutorials): request the business objects, close the session and reattach the objects (which means I keep them somewhere in a Collection) when the user requests the page again. But that means I'm caching my business objects some way, while I'm pretty sure that this was done by the HibernateSession in Hibernate 2.1 (of which I migrated after which all the trouble started).

Hope someone could clarify this for me, because I can't make up what I have to do now from the documentation (guess I'm not as smart as I've always hoped to be).

Sincerely,

Benny 'Malavon' Goemans[/code][/i]


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 07, 2005 5:20 pm 
Regular
Regular

Joined: Thu Dec 02, 2004 7:11 am
Posts: 85
You should separate visual state from business state. Visual state belongs to visual components and should be saved in user session. Having property isSelected in domain object - this is a clearly a mistake. Instead, is you want to maintain list of selected domian objects, then in visual components you can save list of IDs.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 08, 2005 7:29 am 
Newbie

Joined: Mon Mar 07, 2005 9:51 am
Posts: 3
Well, it's correct what you say, not putting the presentation states in the business objects. But how would I go for a business state that is not saved in the database then? It's not exactly my problem, but I'm still wondering how that would be done.


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.