mkuff
mkuff

Reputation: 1682

How can I select objects by list size in HQL?

My entity is defined like this:

public class Entity implements Serializeable {
      @ManyToMany(mappedBy="entities")
      private List<OtherEntity> otherEntities;

}

How can I select in HQL all Entities which have more than one OtherEntity?

Upvotes: 2

Views: 3013

Answers (1)

gkamal
gkamal

Reputation: 21000

I think this should work. This will generate a SQL with a subquery - not fetch it and filter it in memory.

from Entity e where e.otherEntities.size > 1

Upvotes: 6

Related Questions