Best way to design entity beans


EJB design: Best way to design entity beans

  1. Best way to design entity beans (4 messages)

    I'm working on implementing entity beans in our application. What are the best practices for designing entity beans? Should I design entity beans to model database tables or views? Thanks.

    Threaded Messages (4)

  2. another question[ Go to top ]

    Or can I map one entity bean to multiple tables?
  3. another question[ Go to top ]

    The answer is "it depends". As a rule, I try to keep things simple, and map one Entity class to one table. I try to look for optimizations, though, where it makes more sense to map an Entity to data in multiple tables. This is especially common when the database is heavily normalized, and the data for a single business concept is spread across multiple tables.

    An alternative for databases that support updatable views is to create a view for multi-table business concepts, and map your Entity to the view. I have not done this myself, but I have heard that it can be very effective (more performant and more flexible than multi-table Entities).
  4. reply[ Go to top ]

    What are the requirements for the multiple tables. They don't have to be joined I guess.
  5. reply[ Go to top ]

    For CMP EJBs, the precise requirements depend on the EJB server. In practice, they tend to map to a join across the tables, where a query will return exactly one record. Therefore, they are pretty similar to database views.

    For BMP EJBs, you can do anything you like, but you pay for it in added complexity and reduced performance.