cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bruno René Santos <>
Subject Re: Querying on Inherited Objects
Date Sun, 06 Mar 2011 12:18:34 GMT
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?


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

Bruno René Santos | <> | 
Gestor de Projectos | Analista | Programador | Investigador

Holos - Soluções Avançadas em Tecnologias de Informação S.A.
Parque de Ciência e Tecnologia de Almada/Setúbal . Edifício Madan Parque
Rua dos Inventores . Quinta da Torre . 2825 - 182 Caparica . Portugal
Phone: +351 210 438 686 . Fax: +351 210 438 687 . Web:

This email and any files transmitted with it are confidential and 
intended solely for the use of the individual or entity to whom they are 
addressed. If you are not the intended recipient or the person 
responsible for delivering the email to the intended recipient, be 
advised that you have received this email in error and that any use, 
dissemination, forwarding, printing, or copying of this email is 
strictly prohibited. If you have received this email in error please 
notify Bruno René Santos by telephone on +351 210 438 686

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message