0

Is it possible to make a hibernate search query to find substrings of a class field varibles. For example:

public class User {

private String username = "asoftdrink";

}

and make a hibernate query to find all objects of class User which cointains the substring "soft" in their variable username.

1 Answer 1

1

Take a look at Restrictions.like()

criteria.add(Restrictions.like("username", "soft", MatchMode.ANYWHERE));

This is equivalent to

where username like '%soft%'

in SQL. Keep in mind, though, this won't be very efficient since the database can't use an index to execute the query.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I'll try this out. Are there some more efficient ways?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.