org.hibernate.criterion.Example use with CriteriaQuery

主宰稳场 提交于 2021-02-07 18:18:17

问题


I have following code that I need to refactor for use in hibernate 5. This includes removing every deprecated call.

public List<T> findByExample(T example, String... excludeProperty) {   
    Criteria crit = session.createCriteria(T.class);
    Example ex = Example.create(example);
    for (String exclude : excludeProperty) {
        ex.excludeProperty(exclude);
    }
    crit.add(ex);
    return crit.list();
}

Since createCriteria is deprecated I was going to replace it with getSession().getCriteriaBuilder().createQuery(Foo.class);. This is in theory the right way to do it, but now I have no idea how to go about the Example and how it is used in the code.

Can anyone help me to use the Example with hibernate 5?

来源:https://stackoverflow.com/questions/51082428/org-hibernate-criterion-example-use-with-criteriaquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!