tags:

views:

55

answers:

1

The setting is a typical MVC J2EE application, with DAOs for data access.

There are a number of type entities, for instance for a Product bean there is a ProductType member bean, both persisted.

When I am persisting a Product bean, I want to populate it with ProductType info. I have the status code, but do I have to go to the database to retrieve the entire ProductType bean just to populate the Product with type data? Is there a pattern to deal with this kind of type info situation?

I don't want a separate DAO for each of my types, but if I have to pull them explicitly (not implicitly through Product, for example) then I will need one.

Options? Thanks!

A: 

Are the ProductTypes dynamic? That is, do you want to add more types in the future? If that is the case then you need a DAO for the Type in any case.

As far as I understand you will have to load the ProductType instance from the database, add it to the Product that you wish to persist and then save the Product.

If the number of Types are not dynamic then you could consider an enum instead of persisting them to your database. However, in my experience Types tend to be dynamic. Even if you can only think of two possible types of products today, tomorrow management will want another type.

So I would suggest that you write the DAO for the ProductType.

Vincent Ramdhanie
Yes the types are dynamic enough not to use enums.It's a pity to have to create extra daos for this, but I guess it was unavoidable.Thanks.
bowsie