Hi all,

I have a question about what should be the best way to use hibernate
session in tapestry.

My environment consists of 2 layers (relevant to this).

The first one would be a group of classes that represent an access point to
a table. For example if I have a table student then I will have a class
DAOHibernateStudent. This class receives Session object in its constructor.
Doing it this way I can separate all of the queries that are available for
that table into its own class.

The second layer is a class called Manager that implements business logic.
This layer has fields that represent different DAOHibernate* classes. They
are all passed down using constructor. This way I can keep my business
logic in a special class which will communicate with different table
using different DAOHibernate* objects

I use @Inject annotation to inject manager into a page

Lets imagine that I want to create a new Student. So my code would call a
Manager's method createStudent(some data) which would then use a few of the
DAO classes to do all sorts of stuff (e.g. create a student, register
subjects for him, assign him a mentor, add him to a student group, send
notification email and so on...).

The problem that I see here is that since all of those DAO classes are
independent I need to use few Session objects as each one will receive its
own session object. So here are my questions.


   1. Will every time when someone loads/refreshes/opens the page a new
   Manager class be created which will in return create a new DAOHibernate*
   objects and each one will receive a new Session object?
   2. Is it a good idea to use different session objects for the same
   transaction I guess (yea I know that it is not good idea so moving to the
   next question)
   3. How should this problem be solved? Should I pass new session object
   to manager and then pass it as a method parameter to the DAOHibernate*
   4. Any general tips about this approach?

Thanks all,

Cheers

-- 
Sincerely
*Boris Horvat*

Reply via email to