Querying Collections Of Value Type In The Criteria API In Hibernate

- 1 answer

In my database, I have an entity table (let's call it Entity). Each entity can have a number of entity types, and the set of entity types is static. Therefore, there is a connecting table that contains rows of the entity id and the name of the entity type. In my code, EntityType is an enum, and Entity is a Hibernate-mapped class.
in the Entity code, the mapping looks like this:

        name = "ENTITY-ENTITY-TYPE",
        joinColumns = @JoinColumn(name = "ENTITY-ID")
public Set<EntityType> getEntityTypes() {
    return entityTypes;

Oh, did I mention I'm using annotations?
Now, what I'd like to do is create an HQL query or search using a Criteria for all Entity objects of a specific entity type.

This page in the Hibernate forum says this is impossible, but then this page is 18 months old. Can anyone tell me if this feature has been implemented in one of the latest releases of Hibernate, or planned for the coming release?




select entity from Entity entity where :type = some elements(entity.types)

I think that you can also write it like:

select entity from Entity entity where :type in(entity.types)