5

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?

XtremeBaumer
  • 6,275
  • 3
  • 19
  • 65
  • Did you ever find a solution? – BernhardWebstudio Sep 05 '19 at 19:36
  • None using `Example`. I did create a workaround using reflection. Though my solution has been enhanced by colleague lately – XtremeBaumer Sep 06 '19 at 06:12
  • Alright, just as I thought, thanks. The Example was not much more than reflection anyways, as far as I know. Any chance to post your solution as an answer to this question? Otherwise, I can post mine when it is finished, but it will take some time. – BernhardWebstudio Sep 06 '19 at 07:44
  • Hasn't this become more urgent for many of us since the arrival of Spring Boot 3, containing the update to Hibernate 6? A solution without Example is needed - does anybody have one? – Darkwyng Apr 27 '23 at 09:18

0 Answers0