Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Generic CRUD service bean  RSS feed

Piotr Nowicki
Ranch Hand
Posts: 611
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy Ranchers!

I'm a beginner in EJB world, so I will be glad for your advice how to solve this problem. Thanks in advance!

I use many business objects in my application, where a great vast of them use the basic CRUD operations. I'm looking for some unified way to implement those basic features.

In other words, there is a solution proposed by Adam Bien (

The generic interface is fine, but I still need to implement basic operations for each of my Business Objects.
The second solution (bean implementation) is great, but... how should I use it?

1. Should I use composition and inject this CrudServiceBean into mine business object and perhaps delegate all CRUD operations to this EJB, somewhat like this:

In this way I still need to write every CRUD method in my business object class (just a delegation but still in 90% it's just the same plain delegation code).

2. I can extend the CrudServiceBean like the code below:

Can I extend another EJB?
If I cannot, than this CrudServiceBean must be a POJO and therefore it will not have EntityManager injected. This sucks pretty badly...

3. I can extend the CrudServiceBean (plain POJO) and modify it to use a method like getEntityManager() within:

However, in this solution the getEntityManager() method must be at least package-visible (because of the overriding method from business object). I am not sure if this is the correct approach, as it exposes the EntityManager for other BusinessObjects...

Which approach would you choose and what is the rationale?

Thanks in advance!

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!