I would like to create a service which will perform a auditquery with envers.
After trying to find informations I used this code:
@Service
@Transactional
public class SecurityAuditService {
private final Logger log = LoggerFactory.getLogger(SecurityAuditService.class);
@PersistenceContext(type = PersistenceContextType.EXTENDED)
EntityManager entityManager;
public String findAll() {
List query = AuditReaderFactory.get( entityManager )
.createQuery()
.forRevisionsOfEntity(MyClass.class, false, true)
.setFirstResult(4)
.setMaxResults(2)
.getResultList();
But I have a java null exception with entityManager when trying it. How I could use the existing database session to perform my query?
Thanks,
Alain
entityManager
field is not not injected by Spring, add it to SecurityAuditService
's constructor or annotate it with @Autowired