Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How many entity beans to create for more than one table?

 
Bruce Jin
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I need to pull data from several tables with joins, I use one sql query string with join clauses. Can I create a single entity bean to present this “joined table”?
Thanks
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bruce Jin:
When I need to pull data from several tables with joins, I use one sql query string with join clauses. Can I create a single entity bean to present this “joined table”?
Thanks

It depends on your Object-to-Relational mapping implementation (or you, yourself if you're using BMP). Most implementations map one entity bean to a single table, though.
 
Byron Estes
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may want to take a look at "Core J2EE Patterns". It does a nice job discussing things like this at a high level and even provides a section on design considerations and bad practices. On the the practices the book says should be avoided is "Mapping Relational Model Directly to Entity Bean Model". EJB was intended to be for course-grained objects. Created entity beans at the table level produces (in general) a very fine grained approach. Modeling a entity bean for a row in a single table can result in scalabilty problems if your processing results in the retrieval/manipulation of a large result set where each row is an entity bean.
Regards,
 
Bruce Jin
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
I just got Core J2EE Patterns and I will go through it.
 
Byron Estes
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome. After you read it, if you still have questions or want to discuss it, feel free to email me directly.
Best,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic