-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJpaUtilsRemoveTest.java
More file actions
37 lines (31 loc) · 939 Bytes
/
JpaUtilsRemoveTest.java
File metadata and controls
37 lines (31 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.cpucode.test;
import com.cpucode.domain.Customer;
import com.cpucode.utils.JpaUtils;
import org.junit.Test;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
/**
* @author : cpucode
* @date : 2021/3/14
* @time : 21:30
* @github : https://github.com/CPU-Code
* @csdn : https://blog.csdn.net/qq_44226094
*/
public class JpaUtilsRemoveTest {
@Test
public void test1(){
// 获取实体管理对象
EntityManager entityManager = JpaUtils.getEntityManager();
// 获取事务对象
EntityTransaction transaction = entityManager.getTransaction();
// 开启事务
transaction.begin();
// 执行操作
Customer customer = entityManager.find(Customer.class, 1L);
entityManager.remove(customer);
// 提交事务
transaction.commit();
// 释放资源
entityManager.close();
}
}