-->
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: projection and discriminator values
PostPosted: Thu Oct 02, 2008 4:42 pm 
Newbie

Joined: Thu Oct 02, 2008 3:51 pm
Posts: 1
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...


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.