I've searched all over for the answer to this question, and can't find any answers. I feel like the answer should be obvious, but I've tried everything I can think of. Here's the problem:
I have a class, ApplicationEvent, that contains an Endpoint object, with a many-to-one mapping. Endpoint is actually an abstract superclass; I only instantiate its subclasses, EndpointA and EndpointB. All I want to do is to create a Criteria query that finds all ApplicationEvents with an Endpoint of type EndpointA.
I've tried all sorts of things trying to get this to work. When I try criteria.add(Restrictions.eq("endpoint.protocol","A"), I get a HibernateQueryException: could not resolve property: endpoint.protocol of: ApplicationEvent. The same thing happens when I try "e.endpoint.protocol" or just "protocol". Any time I start with a criteria.createCriteria("endpoint") construct, I get a HibernateQueryException: duplicate association path. The same thing happens if I use createAlias("endpoint", "ep"). I tried various permutations with Projections, subqueries, etc., but nothing worked. If anyone can tell me the proper semantics to do this, I'd be greatly appreciative.
Thanks in advance. My mapping file follows:
Code:
<class name="Event" table="aud_event" discriminator-value="EVENT">
<id name="id" column="id">
<generator class="native"/>
</id>
<discriminator column="event_type" type="string" />
...
<subclass name="ApplicationEvent" discriminator-value="APPLICATION_EVENT">
<join table="aud_application_event">
<key column="id" />
<property name="appId" column="appid" />
...
<many-to-one name="endpoint" column="endpoint" class="Endpoint" not-null="true" lazy="false" />
</join>
</subclass>
</class>
<class name="Endpoint" table="usr_endpoints">
<id name="id" column="id">
<generator class="native"/>
</id>
<discriminator column="protocol" type="string" />
<subclass name="EndpointA" discriminator-value="A" >
...
</subclass>
<subclass name="EndpointB" discriminator-value="B" >
...
</subclass>
</class>