struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ken <ken.mcwilli...@aerose.com>
Subject Re: Session object null
Date Tue, 18 May 2010 22:55:31 GMT

Thank you,
The problem has been resolved with what you said...
However I'll fill you as I am new and looking for best practise.

On Tue, 2010-05-18 at 15:25 -0400, Dale Newfield wrote:

> On 5/18/10 2:17 PM, Ken wrote:
> > Let me see if I understand this correctly.  Since the action object has
> > not been created yet, and this is in a different thread... I can not get
> > the correct context...  Although the session objects _is_ someplace...
> > It will also not work in the constructor even if the class is
> > SessionAware because the object must exist before setSession(Map m)
> > could be called...
> 
> You've not provided much context regarding the life cycle of the object 
> you're trying to create, where it is created/used/stored, etc.  So it's 
> tough to answer specifically.  There are numerous scopes in which 
> objects of varying lifespans can be stored.  It sounds like your object 
> is a per-session object, even though you're going through a request to 
> create it?  Are there reasons it needs external resources (DB 

Most requests are DB queries, via Hibernate.  There is a Hibernate
configuration file that needs to be loaded that specifies connection
parameters and the tables to include.  In our system there are many
databases, one for each company (some are holding companies)...  So
there are a number of configuration files, depending on the log-on
credentials a different database is loaded (some users may be able to
select which one they are working with)... The processing is more less
consistent, the databases hold different accounting information for the
particular company. Anyways this configuration object and/or the
resulting SessionFactory (Hibernate connection sessions not Struts2)
aught to be in session scope.  Currently these objects are only stored
in memory and obtained with new in the request cycle.

So to think about it I'm currently creating a hibernate SessionFactory
EVERY request from credentials supplied by the log in form and then
throwing it away... well I'm going to change that.  So it isn't an
issue... but knowing what I'm doing any advice on how you'd do it?

There is nothing fancy, just the struts mapping file and actions with
the default stack.  And for view jsp's templated with tiles.  I've only
just started but I have to say everything has been far easier than
expected... So I'm really enjoying Struts2.

Do you use Spring? I've heard great things about it.  


> connection, etc.) that would mean it should be created and destroyed on 
> a per-request basis (most reliable, don't have to worry about 
> storage/serialization/clusters/etc.)?  Are there reasons it needs to 
> live longer than the request?
> 
> > So...
> > I should really be treating execute() as my constructor for now... until
> > I better understand when the session variable becomes available.
> > Struts2 needs to see who I am before it knows my session right?  So it
> > isn't going to provide it to me until it has done a certain amount of
> > set up?
> 
> There are hooks for lots of different events, from application startup 
> to session creation, to request processing, etc.  The important part is 
> to figure out your requirements, then we can suggest where to do the 
> work/store the object.
> 
> -Dale





Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message