In fact, this is not making much sense here:
@Autowired
private AtividadeRepository atividadeRepository;
private AtividadeDAO atividadeRepository = new AtividadeDAO();
Incidentally, it would not even compile since you are declaring two different objects with the same name within the scope of the same class.
Another thing is that you are probably making some confusion of concepts. Either you use a repository, or you use a DAO. Repositories are entities that work at the collection level. DAOs are entities that work at the level of database technology.
In addition, the difference between Data Access Object (DAO) and Data Access Layer (DAL) is not just one letter: DAO is the object that is part of a DAL. Normally, both DAO and a repository return DTO ( Data Transfer Object >) objects.
Having this understood, we can move to @Autowired
.
@Autowired
is the annotation for Dependency Injection . It indicates to the framework that the marked object will be managed by the framework (its entire lifecycle). It makes sense for a Service
, but it does not make much sense to an entity, since usually an entity (most of the time) is an anemic object that does not require life cycle management (DTO definition).
So in this case, I think it would be interesting to remove the DAO statement.