<p>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.<br>
in the Entity code, the mapping looks like this:</p>

<pre><code>@CollectionOfElements
@JoinTable(
        name = "ENTITY-ENTITY-TYPE",
        joinColumns = @JoinColumn(name = "ENTITY-ID")
)
@Column(name="ENTITY-TYPE")
public Set&lt;EntityType&gt; getEntityTypes() {
    return entityTypes;
}
</code></pre>

<p>Oh, did I mention I'm using annotations?<br>
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.<p>
<a href="http://opensource.atlassian.com/projects/hibernate/browse/HHH-869?page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel" rel="nofollow noreferrer">This</a> 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?</p>

[{'answer_id': 50402, 'author': 'Hank Gay', 'author_id': 4203, 'author_profile': 'https://Stackoverflow.com/users/4203', 'pm_score': 0, 'selected': False, 'text': '<p>Is your relationship bidirectional, i.e., does <code>EntityType</code> have an <code>Entity</code> property? If so, you can probably do something like <code>entity.Name from EntityType where name = ?</code></p>\n'}, {'answer_id': 53405, 'author': 'marcospereira', 'author_id': 4600, 'author_profile': 'https://Stackoverflow.com/users/4600', 'pm_score': 2, 'selected': True, 'text': '<p>HQL:</p>\n\n<pre><code>select entity from Entity entity where :type = some elements(entity.types)\n</code></pre>\n\n<p>I think that you can also write it like:</p>\n\n<pre><code>select entity from Entity entity where :type in(entity.types)\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/49334', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2819/']