-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Criteria restriction on discriminator column?
PostPosted: Sat Feb 24, 2007 10:43 pm 
Newbie

Joined: Sat Feb 24, 2007 10:16 pm
Posts: 4
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>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.