The EJB Session Bean for wrapping the JPA Entity
My expectation is generating the JPA Entity by using the NetBeans or other tools. It does not suppose to be modified by hand. If there is any changing at the database layer, I will regenerate it.
I decide to create a EJB Session Bean for wrapping the basic functions for integrating with the JPA Entity, The set of Create, Read, Update , Delete (CRUD) functions, especially the variety of finding function. I hope it may help to increase the transparent JPA Entity changing. I treat this session bean as an interface for any required integrating by the other through the JPA entity, as long as there is no interface changing, there is also no the client changing, too.
Furthermore, this session bean should be accessed locally, since the other should not know how to manage this JPA entity. The difficulty and complexity should be hidden by wrapping as a business services, note I will update about it later.
I create the interface by annotating it as @Local to ensure the local accessing. The good news is the session bean can be derived from any POJO. I also wrap the common activity to the abstract class which implements that interface. The wrapping session bean will be derived from this abstract class and it is annotated as @Stateless
@Local is an annotation for the interface and declaring it to be accessed locally.
@Stateless is annotation for the POJO and declaring it to be a stateless session bean.