|
Hi forum,
I would like to know what strategies people
use in real life to design their entity beans, when use CMPs and when BMPs. Each
approarch has its own benefits and drawbacks.
This is what I found out during my experience with
EJB:
1.CMPs
Benefits:
- easy to
develop;
- better
perfomance.
Drawbacks:
- less flexible then
BMPs;
- some of the queries
cannot be performed with pure CMP, so sometimes it is necessary to add a
data access object ( java class ) that uses JDBC to directly communicate with
database ( to retreive the number of records etc. ). The problem here is that it
is necessary
- not all queries can be coded
with CMP finder methods ( consider example: I need to extract 20 records,
starting with 500 out of 3000 records in a table. Using Collection would be
extremely expensive ).
2.BMPs
Benefits:
- full control over data
flow. you can do anything JDBC is capable of.
Drawbacks:
- huge perfomance
degradation when retrieving a collection of BMPs - the problem of n+1
call.
My conclusion is: everyting is fine with the
creation, updating and deleting the entities. The problem arises with finder
methods: You are either to slow with BMPs or fast with CMPs but with limited
functionality. Another idea is to use CMPs to create/update/delete entities, but
use JDBC and retreive collections values value objects for finders,
something like:
public class EntityValue {
public int
id;
public String
data;
}
The problem here is that we lose encapsulation...
How do you handle this situation?
Any suggestions are very much
appreciated.
Sergei.
|
