spring entitymanager createqcriteria code example

Example 1: spring boot entitymanager example

entityManager.getTransaction().begin();
		entityManager.remove(emp);
		entityManager.getTransaction().commit();

Example 2: spring boot entitymanager example

EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("persistence");
		EntityManager entityManager = entityManagerFactory.createEntityManager();
 
		entityManager.getTransaction().begin();
		Employee employee = new Employee();
		employee.setName("Sanjay");
 
                // Save Entity
		entityManager.persist(employee);
		entityManager.getTransaction().commit();
		System.out.println("Generated Employee ID = " + employee.getEmployeeId());

Tags:

Misc Example