cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marcin Skladaniec <mar...@ish.com.au>
Subject Re: Querying on Inherited Objects
Date Mon, 07 Mar 2011 22:24:22 GMT
Hi Bruno

All squares are rectangles, but some rectangles are squares, the query 
for rectangles will also give you squares. This is a valid result from 
cayenne's perspective.

What you looking for is to query for Rectangle but not Square. I see 
three ways of doing that:
- query for Parent, query for Child, subtract results from each other. 
(performQuery(Rectangle).removeAll(performQuery(Square))
- create another subclass of Parent, mutually exclusive with Child, and 
query that. (performQuery(NotSquare))
- expose the qualifier field in cayenne modeler, query with the 
qualifier. (performQuery(Rectangle, 
ExpressionFactory.noMatch(polygonType, square))


With regards
Marcin



On 6/03/11 11:18 PM, Bruno René Santos wrote:
> Both parent and child are the same on the database level. But each 
> object is used differently on the GUI level. As both GUIs must 
> cohexist temporarily I thought I could do a child object from the 
> current used object and change some logic on it. So i got something 
> like this
>
> Child extends _Child
>
> _Child extends Parent
>
> Parent extends _Parent
>
> _Parent extends CayenneDataObject
>
> The only issue here (at least I think...) is that a performQuery(new 
> SelectQuery(Child.class)) will correctly return a list of Child but a 
> performQuery(new SelectQuery(Parent.class)) will also return a List of 
> Child... Any way to return a List of Parent?
>
> Thanx
> Bruno
>
> Em 06-03-2011 10:15, Aristedes Maniatis escreveu:
>> On 6/03/11 9:03 PM, Bruno René Santos wrote:
>>> I have an object structure with a Child dataobject which inherits 
>>> from a Parent which is linked to a db_entity. I am trying to use the 
>>> Parent on a GUI and the Child on another GUI. The Child overrides 
>>> some methods from the Parent (but the db table is the same) and so 
>>> is mandatory that on each GUI their respective searches yeld Child 
>>> objects or Parent objects. On the GUI that uses the Child everything 
>>> goes according plan, the performQueries return lists of Children. 
>>> But on the Parent GUI I call
>>>
>>> context.performQuery(new SelectQuery(Parent.class))
>>>
>>> but the method returns also a list of Children, which are 
>>> incompatible with the parent GUI. Is there any way that this query 
>>> returns Parents instead of Children? I was trying these inheritance 
>>> so that i could reuse all db fields and relationships from the 
>>> parent on the child.
>>
>> What does the discriminator column say about these objects? Are they 
>> actually Child entities in the database or Parent? They can't be both 
>> at the same time.
>>
>> This isn't like plain-old Java inheritance where you can just cast 
>> from one to the other as needed. If you could, what would happen if 
>> you queried for a list of Child objects, casting them as Parents, 
>> changed some Parent attribute and committed the context? Would they 
>> now become Parents in the database?
>>
>> Ari
>>
>>
>
>



Mime
View raw message