On 5/18/10 6:55 PM, Ken wrote:
The problem has been resolved with what you said...

Glad to hear it.

However I'll fill you as I am new and looking for best practise.

I can offer my advice, but I don't have the hubris to claim that's necessarily what others would agree to as best practice. :-)

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?

Just to confirm--you have a single database that contains the login info, and based on info there other data will come from different databases? I almost went a similar route on a project but decided the headaches weren't worth it, so I've got entirely separate deployments for each end application (and that's OK for me -- sounds like your requirements require another solution).

This sounds like it would best fit in an interceptor, probably before "params" (or if you use "params prepare params" between the first params and the prepare) so that by the time you get to prepare (and at least the last params) you've already got a connection to the correct DB so you can store incoming fields directly in the model object. Depending on the tradeoff between the cost to construct this SessionFactory and the size/resources required to store it in the session between requests you can either have this interceptor create it anew each request or cache it in the session, only creating it if necessary.

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.

Glad to hear it!

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

For dependency injection, for example, it is quite nice.

I used "appfuse" to jump-start most struts2 apps I've built, so the configuration headaches are minimized...but you've already figured out the hard parts of your particular DB situation, so that shouldn't be too bad...

-Dale

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to