问题
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