Created
August 21, 2023 11:44
-
-
Save azizkale/5f1bc9ca61fdef84d8097a9fde78ae2c to your computer and use it in GitHub Desktop.
the article - How to implement Hibernate in Spring Boot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.kale.hibernatetutorial.dao; | |
import com.kale.hibernatetutorial.model.Employee; | |
import jakarta.persistence.EntityManager; | |
import jakarta.persistence.PersistenceContext; | |
import org.springframework.stereotype.Repository; | |
import java.util.List; | |
@Repository | |
public class EmployeeRepositoryImpl implements EmployeeRepository { | |
@PersistenceContext | |
private EntityManager entityManager; | |
@Override | |
public List<Employee> findAll() { | |
return entityManager.createQuery("from Employee",Employee.class).getResultList(); | |
} | |
@Override | |
public Employee findById(int id) { | |
return entityManager.find(Employee.class,id); | |
} | |
@Override | |
public void create(Employee employee) { | |
entityManager.persist(employee); | |
} | |
@Override | |
public void delete(int id) { | |
entityManager.remove(entityManager.getReference(Employee.class,id)); | |
} | |
@Override | |
public Employee update(Employee employee) { | |
return entityManager.merge(employee); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment