• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Generic CRUD service bean

 
Ranch Hand
Posts: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 (http://www.adam-bien.com/roller/abien/entry/generic_crud_components_with_java).

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!

Cheers!
 
Evildoers! Eat my justice! And this tiny ad's justice too!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic