Paul Sideleau wrote:
I have a design question regarding a POJO entity bean,
dependency injection, and storing the POJO in the
user's session.
For example, there is a web application where you
update some entity through several "wizard" like
screens. Then, this information is persisted to a
database. The information is stored in a POJO entity
bean that uses a data access object to persist the
data.

If your bean needs its DAO to be injected, I don't think
it's really a POJO. It's coupled to your DAO and I can't
re-use your class without also using your DAO framework.
If you mean that your class is an entity bean in the
EJB sense, then it's definitely not a POJO, being
coupled to that framework too (for some value of EJB).

A real POJO contains business logic and data and doesn't
need to know anything about how it's stored.

Another option that I can think of would be to use a
simple value bean/transfer object to maintain state
and store that in the user's session. Then, create the
entity bean at the end and pass the value bean to the
entity bean. However, several articles and books have
warned against using transfer objects.

The main objection to DTOs, at least as I understand it,
is that they duplicate domain objects. Use real POJOs
(to store in the database and pass around between layers)
and you're avoiding this issue.

Which is the best option or is there another option
that I have not thought of?

I think this is the best option. Rather than your bean knowing
how to store itself, just use your domain class (the bean that
actually gets stored in the database). Store it in the session
and when it's time to save, pass it to a service object which
knows how to persist it. Separation of concerns in this way
makes testing much easier. The POJO can be fully tested with
unit tests, and the service object can be tested with mocks
or just with functional tests that inspect the database after
each operation.


Jon.
--
.....................................................................
          Dr Jonathan Harley   .
                               .   Email: [EMAIL PROTECTED]
           Zac Parkplatz Ltd   .   Office Telephone: 024 7633 1375
           www.parkplatz.net   .   Mobile: 079 4116 0423

Reply via email to