0

I am new to hibernate and looking for a) A solutions and b) comparison of solutions in terms of performance and query complexity.

Example entity - (Assume required hibernate annotations)

Class Ent{
String name;
List<String> alias;
}

I need a solution which can search for a string 'example' in name and alias array in a single database query.

I am able to do this using hibernate with RAW sql ( select * ...). Can somebody suggest a better solution using HQl, Criteria, etc.. with reason

1
  • I believe you wanted to say HQL.. I tried using HQL but facing issues as hibernate is not supporting ANY operator present in SQL. I am working with the IN operator.. Commented Jan 16, 2016 at 18:24

1 Answer 1

1

Assuming that alias can be empty:

select distinct e from Ent e left outer join e.alias a 
where e.name like :term or a.name like :term

or:

select e from Ent e
where e.name like :term
 or e.id in
  (select e2.id from Ent e2 join e2.alias a where a.name like :term)

I prefer the second option because it should be faster (no distinct) and because it allows easier paging of the results.

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

Comments

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.