jeudi 17 août 2017

Simple logic in Spring Entity getter?

I have a User entity which has a one-to-many relationship with UserSkill entity. UserSkill can be active and inactive (inactive is set upon skill deletion, instead of deleting it completely). The thing is, that most of the time active skills are important for end user (inactive may be used later for statistical purposes). Having that in mind, when I query User entity from the database, most of the time I want to access only active skills through it.

My question is, which implementation is better:

  1. I have getUserSkills (simple getter) and getActiveUserSkills (getter with some filtering) on the User entity, and use getActiveUserSkills most of the time. (Everyone seems to keep telling that POJO should be POJO, no additional logic.)
  2. I have userSkillService, and I have getActiveUserSkills(User user) method, which returns only active user skills. I then use these active skills along with User when I need them. The problem here is that every time I get User, I will have those unnecessary inactive skills with it.

Other implementation suggestions are also welcome. Thanks !

Aucun commentaire:

Enregistrer un commentaire