Hello,
We are working with version 3.2.3ga
I am wondering if it's possible to set a Projection on a property that is subclassed by discriminator?
I have these mappings:
<class name="xx.yy.Default" entity-name="Default" table="DEFAULT_V">
<!-- Primary Key -->
<id name="oid" column="OID"></id>
...
<many-to-one name="customer" class="xx.yy.Customer" insert="false" update="false">
<column name="CUSTOMER_OID" />
</many-to-one>
</class>
<class name="xx.yy.Customer" table="CUSTOMER_V" discriminator-value="-1" abstract="true" lazy="false">
<id name="oid" type="java.lang.Long" column="CUSTOMER_OID"
unsaved-value="0">
</id>
<discriminator column="TYPE_CODE" type="int"/>
...(properties omitted)...
<subclass name="xx.yy.Person" discriminator-value="1" extends="xx.yy.Producer"
select-before-update="true" lazy="false">
... (properties omitted)...
</subclass>
<subclass name="xx.yy.Business" discriminator-value="null" abstract="true"
select-before-update="true" lazy="false">
<subclass name="xx.yy.Partnership" discriminator-value="2"/>
<subclass name="xx.yy.Corporation" discriminator-value="3"/>
</subclass>
</class>
I am trying to code up a Criteria query on the Default object, doing a projection on the "customer" property as that's the only property I need. It's a Criteria query because the specified search criteria can be any combination of Name and/or Address and/or Phone number etc and that would be tough thru HQL
My dilemna is that part of the search criteria is also the "type" of customer (Person vs. Business), but can't figure out how to specify that part. I end up getting all Customer types, even though I only want (let's say) a Person. Essentially, my generated sql is missing the following line:
"and TYPE_CODE = 1" (assuming I'm going after a Person specifically).
What am I missing? Here's the first part of my Criteria query - I omitted the name/address/phone# search stuff.
Criteria criteria = session.createCriteria("Default", "default" ); criteria = criteria.setProjection(Projections.property("customer")); criteria = getSearchCriteria(session, criteria, customerSearchCriteria);
Don't know to to handle this with Projection. Any guidance would be greatly, greatly appreciated. Thanks in advance!.
BTW - Love the use of "Fritz the Cat" in the Reference Documentation examples...classic cartoon...
|