我是刚开始使用Spring Boot和JPA缓存(第一级和第二级缓存)的人 我的项目配置为Spring boot starter和JPA。 我正在尝试使用一级缓存。但它不起作用。
@Service
public class CacheService {
@Autowired
EntityManagerFactory emf;
public CacheEntity getAll(){
EntityManager em =emf.createEntityManager();
EntityTransaction emt = em.getTransaction();
emt.begin();
CacheEntity trainer = em.find(CacheEntity.class, "TRAINER-0005");
CacheEntity trainer1 =em.find(CacheEntity.class, "TRAINER-0005");
emt.commit();
em.close();
return trainer;
}
}
这里是我的实体类定义为:
@Entity
@Table(name = "TRAINER")
public class CacheEntity {
@Id
@Column(name = "TRAINIID")
private String trainiId;
@Column(name = "FIRSTNAME")
private String trinifirstname;
@Column(name = "LASTNAME")
private String trainilastname;
@Column(name = "PHONENUMBER")
private String trainiphno;
@Column(name = "STATE")
private String trainistate;
@Column(name = "CITY")
private String trainicity;
@Column(name = "QUALIFICATION")
private String trainiqualification;
}
我正在尝试使用相同的主键从数据库中获取数据,但是由于您中的任何人都知道我犯了什么错误,请查询两次。
休眠:选择cacheentit0_.TRAINIID作为TRAINIID1_12_0_,cacheentit0_.CITY作为CITY2_12_0_,cacheentit0_.LASTNAME作为LASTNAME3_12_0_,cacheentit0_.PHONENUMBER作为PHONENUM4_12_0_,cacheentit_0 _._ LOCAL_ENT_0_RAIN_ENT_0_STATE_0_RAIN_ENT_0_STATE_ENT_0_QUALIFICATION作为QUALIFICATION作为6的状态。在哪里cacheentit0_.TRAINIID =?
休眠:选择cacheentit0_.TRAINIID作为TRAINIID1_12_0_,cacheentit0_.CITY作为CITY2_12_0_,cacheentit0_.LASTNAME作为LASTNAME3_12_0_,cacheentit0_.PHONENUMBER作为PHONENUM4_12_0_,cacheentit_0 _._ LOCAL_ENT_0_RAIN_ENT_0_STATE_0_RAIN_ENT_0_STATE_ENT_0_QUALIFICATION作为QUALIFICATION作为6的状态。在哪里cacheentit0_.TRAINIID =?