You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by emeka okafor <em...@yahoo.com> on 2013/01/13 13:46:14 UTC

many2many + single table inheritance


Hello again,
I have been trying to simplify some parts of my code and so I figured the following will work:

I have a many-to-many relation, say A <<->> Base
Base has two subclasses, say Base1 andBase2 modeled using single table inheritance,
so basically:
<obj-entity name="Base1" superEntityName="Base" className="Base1">

<qualifier><![CDATA[Type = "BASE1"]]></qualifier>
</obj-entity>
<db-relationship name="bases" source="A" target="Base" toMany="true">
<db-attribute-pair source="A_ID" target="BASE_ID"/>
</db-relationship>

I thought that by adding this:

<obj-relationship name="bases1" source="A" target="Base1" db-relationship-path="bases"/>,

in other words: A -> B1, 

Then I would be able to do A.getBases1() to retrieve all of my subclasses instead of always having to go through A.getBases() and then filter using the discriminator column.
But it is not working. Any idea how to achieve what I am trying to do?
Thanks.

Re: Date or Timestamp

Posted by Michael Gentry <mg...@masslight.net>.
Hi there,

You can choose java.sql.Timestamp in the ObjEntity and TIMESTAMP in the
DbEntity.

mrg



On Mon, Jan 14, 2013 at 2:47 PM, emeka okafor <em...@yahoo.com> wrote:

> I am working with h2 at the moment and the modeler is mapping
> java.util.Date to the database Date type but I would live to have the
> datebase "Timestamp" type. How do I handle this with cayenne?
>

Date or Timestamp

Posted by emeka okafor <em...@yahoo.com>.
I am working with h2 at the moment and the modeler is mapping java.util.Date to the database Date type but I would live to have the datebase "Timestamp" type. How do I handle this with cayenne?

Re: many2many + single table inheritance

Posted by emeka okafor <em...@yahoo.com>.
Yes, I tried what you said and it seems to work in most cases. As my model grows and becomes more complicated, I have to do a lot of fiddling at some places in my code. I think I am going to get rid of inheritance and only work with data.
Thanks lot.


________________________________
 From: Ramiro Aparicio <ra...@prot-on.com>
To: user@cayenne.apache.org 
Sent: Monday, January 14, 2013 10:30 AM
Subject: Re: many2many + single table inheritance
 
I have been working with inheritance a lot lately but finally I had to 
remove it from my model.

If Base is an abstract class you will have problems at deleting A o Base 
child objects.
Anyway in your case you want to make 3 relationships, A<-Base A->Base1 
A->Base2 (the arrows are not for cardinality just to tell where do you 
want to model the relationships) this will render some warnings or 
notices in the modeller, but will work ok with your current usage.

El 13/01/2013 13:46, emeka okafor escribió:
>
> Hello again,
> I have been trying to simplify some parts of my code and so I figured the following will work:
>
> I have a many-to-many relation, say A <<->> Base
> Base has two subclasses, say Base1 andBase2 modeled using single table inheritance,
> so basically:
> <obj-entity name="Base1" superEntityName="Base" className="Base1">
>
> <qualifier><![CDATA[Type = "BASE1"]]></qualifier>
> </obj-entity>
> <db-relationship name="bases" source="A" target="Base" toMany="true">
> <db-attribute-pair source="A_ID" target="BASE_ID"/>
> </db-relationship>
>
> I thought that by adding this:
>
> <obj-relationship name="bases1" source="A" target="Base1" db-relationship-path="bases"/>,
>
> in other words: A -> B1,
>
> Then I would be able to do A.getBases1() to retrieve all of my subclasses instead of always having to go through A.getBases() and then filter using the discriminator column.
> But it is not working. Any idea how to achieve what I am trying to do?
> Thanks.
>

Re: many2many + single table inheritance

Posted by Ramiro Aparicio <ra...@prot-on.com>.
I have been working with inheritance a lot lately but finally I had to 
remove it from my model.

If Base is an abstract class you will have problems at deleting A o Base 
child objects.
Anyway in your case you want to make 3 relationships, A<-Base A->Base1 
A->Base2 (the arrows are not for cardinality just to tell where do you 
want to model the relationships) this will render some warnings or 
notices in the modeller, but will work ok with your current usage.

El 13/01/2013 13:46, emeka okafor escribió:
>
> Hello again,
> I have been trying to simplify some parts of my code and so I figured the following will work:
>
> I have a many-to-many relation, say A <<->> Base
> Base has two subclasses, say Base1 andBase2 modeled using single table inheritance,
> so basically:
> <obj-entity name="Base1" superEntityName="Base" className="Base1">
>
> <qualifier><![CDATA[Type = "BASE1"]]></qualifier>
> </obj-entity>
> <db-relationship name="bases" source="A" target="Base" toMany="true">
> <db-attribute-pair source="A_ID" target="BASE_ID"/>
> </db-relationship>
>
> I thought that by adding this:
>
> <obj-relationship name="bases1" source="A" target="Base1" db-relationship-path="bases"/>,
>
> in other words: A -> B1,
>
> Then I would be able to do A.getBases1() to retrieve all of my subclasses instead of always having to go through A.getBases() and then filter using the discriminator column.
> But it is not working. Any idea how to achieve what I am trying to do?
> Thanks.
>