Although my Java applications were small and did simple things, I was quite pleased with the use of simple SQL, especially since application servers such as Glassfish simplify connection management. After I learned about JPA and EJB, I decided to reorganize my projects so that they use these cool things, but ran into a problem that is more related to design than programming:
Is it good practice to embed behavior in Entity Beans, or should they only store data?
I read a lot of manuals and manuals, but they basically answer how I can use them, and not how I should meet the requirements of good design.
For example, if 2 classes are specified: User and Location , they are both beans objects. A User can store a collection of Location s, and this is normal and easy to implement using JPA. But if I want to fill these classes with some functionality, for example, methods of calculating the distance to another user or location, find their intersections, calculate the distance that User ran for a day, and so on. Will it be a βgood designβ if I implement such functionality in beans myself or should I use special decorators and helper classes with many static methods to achieve my goal?
source share