стасевич
стасевич

Reputation: 398

Could not autowire. No beans of 'EntityManager' type found

trying spring boot, in video said, that the bean for entityManager spring creating automaticly, and in video guy havnt problems. but in my case i have an error Could not autowire. No beans of 'EntityManager' type found.

import javax.persistence.EntityManager;
 
   @Repository
    public class EmployeeDAOImpl implements EmployeeDAO {
    
        @Autowired
        private EntityManager entityManager;//Could not autowire. No beans of 'EntityManager' type found. 
    
        @Override
        public List<Employee> getAllEmployees() {
            Session session = entityManager.unwrap(Session.class);
            Query<Employee> query = session.createQuery("from Employee ", Employee.class);
            List<Employee> allEmployees = query.getResultList();
            return allEmployees;
        }
    

Upvotes: 0

Views: 4190

Answers (1)

Marina Solovieva
Marina Solovieva

Reputation: 21

From version 6.0 Hibernate uses jakarta.persistence rather than javax. Change the import and use the @PersistenceContext annotation

Upvotes: 2

Related Questions