Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate not equal example criteria

Tags:

hibernate

Hibernate has example criteria: For example:

Example equal = Example.create(mydbObject);

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

Example notEqual = Example.createNotEqual(mydbObject);

or anything similar that to create a not equal criteria. I don't want to go through each fields and not Restrictions.ne on it.

Thanks,

like image 416
Sean Nguyen Avatar asked Jan 23 '11 15:01

Sean Nguyen


People also ask

How do you add not equal to in criteria?

Use the SUMIF function and the “not equal to” sign of Excel. The steps to use the SUMIF function. The criteria can include dates, numbers, and text. For example, the formula “=SUMIF(B1:B5, “<=12”)” adds the values in the cell range B1:B5, which are less than or equal to 12.

Can you explain criteria in hibernate?

Hibernate provides alternate ways of manipulating objects and in turn data available in RDBMS tables. One of the methods is Criteria API, which allows you to build up a criteria query object programmatically where you can apply filtration rules and logical conditions.

Why Hibernate Criteria API deprecated?

Hibernate offers an older, legacy org. hibernate.Criteria API which should be considered deprecated. No feature development will target those APIs. Eventually, Hibernate-specific criteria features will be ported as extensions to the JPA javax.


2 Answers

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 .

like image 129
Allan Ruin Avatar answered Oct 06 '22 08:10

Allan Ruin


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

like image 28
Łukasz Rzeszotarski Avatar answered Oct 06 '22 09:10

Łukasz Rzeszotarski