Hibernate not equal example criteria

后端 未结 3 641
盖世英雄少女心
盖世英雄少女心 2020-12-17 16:19

Hibernate has example criteria: For example:

Example equal = Example.create(mydbObject);

Is there a way to do the opposite, For example:

相关标签:
3条回答
  • 2020-12-17 16:20
    Criteria cri = session.createCriteria(Your.class);
    cri.add(Restrictions.not(Restrictions.eq("parameter", "test")));
    

    -- Restrictions.not will be negation of the expression

    0 讨论(0)
  • 2020-12-17 16:31

    Use it with s.createCriteria(YourClass.class).add(Restrictions.not(notEqual));.

    0 讨论(0)
  • 2020-12-17 16:38

    I looking for the same restriction method for "not equal" and according to the document, it's

    List list = getSession().createCriteria("you.pakcage.hibernate.Example")
                            .add(Restrictions.ne("myProperty","blablabla"))
                            .list();
    

    by this way you retreat a list contain all the Example object except those whose myProperty property is "blablabla".

    May be not exactly what you what, but it achieve the same thing for me .

    0 讨论(0)
提交回复
热议问题