如何在spring boot中使用hibernate注释过滤器?

如何在spring boot中使用hibernate注释过滤器?,hibernate,spring-boot,Hibernate,Spring Boot,我想对我的spring boot后端使用hibernate注释过滤器,我使用repos从数据库获取数据,我不知道为什么只获取未过滤的元素,我用过滤器注释配置实体,并在控制器中启用过滤器。有人知道遗漏了什么吗?或者有没有人在spring boot中使用@filter的经验 @CrossOrigin(value = "http://localhost:**") @RestController public class MyController { public MyController(En

我想对我的spring boot后端使用hibernate注释过滤器,我使用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 {}

所以我的问题是我使用了jpa会话(我不知道)而不是hibernate。现在我正在使用hibernate,一切都很好,它可以工作:)

我想
不起作用
意味着你的实体在这里没有被过滤就被加载了?是的,这是我的问题,所以你最好编辑这个问题,使其更具体。另外,我猜SpringBoot和Maven在这里没什么关系,这是一个特定于Hibernate的版本。谢谢你的提示!在您的问题中:FilterDef name=equalId,但在@Filter name=equalId中(不带“l”)。打字错误