我想在我的spring boot后端使用休眠注释过滤器,我正在使用repos从数据库中获取数据,而且我不知道为什么我只得到未过滤的元素,我使用过滤器注释,并在控制器中启用过滤器。有人知道缺少什么吗?还是有人在Spring Boot中使用@filter有一定的经验?
@CrossOrigin(value = "http://localhost:**")
@RestController
public class MyController {
public MyController(EntityManagerFactory entityManagerFactory) {
this.sessionFactory = entityManagerFactory.unwrap(SessionFactory.class);
}
public class MyController {
public MyController(EntityManagerFactory entityManagerFactory) {
this.sessionFactory = entityManagerFactory.unwrap(SessionFactory.class);
}
@ModelAttribute("id")
public String getMandatortId(@RequestAttribute String id) {
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
Filter mandator_filter = session.enableFilter("equalId");
mandator_filter.setParameter("id", id);
return id;
}}
@Entity
@Table(name = "openuser", schema = "arego", catalog = "")
@FilterDef(name = "equalId", parameters = {@ParamDef(name = "id", type = "string")})
@Filters( {@Filter(name = "equalId", condition id = :id")})
@IdClass(PatientEntityPK.class)
public class OpenuserEntity {}
答案 0 :(得分:0)
所以我的问题是我使用jpa会话(我不知道)而不是休眠。现在我正在使用休眠模式,一切都很好,并且可以正常工作:)