You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Dave Lamy <da...@gmail.com> on 2009/09/24 19:10:33 UTC

First time inheritance attempt

Hey guys--

I'm attempting to model some inheritance for the first time and it's not
working yet.  Here's my situation:

My model is to have a non-abstract parent class->table and then
subclass->tables like so:

First I should doublecheck to make sure my mapping XML looks OK:

    <db-entity name="ASSET_CONTENT">
        ...
        <db-attribute name="CONTENT_TYPE" type="VARCHAR" length="50"/>
        <db-attribute name="ID" type="INTEGER" isPrimaryKey="true"
isGenerated="true" isMandatory="true"/>
        ...
    </db-entity>
    <db-entity name="IMAGE_ASSET_CONTENT">
        <db-attribute name="HEIGHT" type="INTEGER"/>
        <db-attribute name="ID" type="INTEGER" isPrimaryKey="true"
isMandatory="true"/>
        <db-attribute name="WIDTH" type="INTEGER"/>
    </db-entity>
    <obj-entity name="AssetContent"
className="com.routeto1.asset.filesystem.AssetContent"
lock-type="optimistic" dbEntityName="ASSET_CONTENT"
superClassName="com.routeto1.data.impl.DynamicDataObject">
        <obj-attribute name="contentType" type="java.lang.String"
db-attribute-path="CONTENT_TYPE"/>
         ...
        <pre-persist method-name="prePersist"/>
    </obj-entity>
    <obj-entity name="ImageAssetContent" superEntityName="AssetContent"
className="com.routeto1.asset.filesystem.ImageAssetContent"
lock-type="optimistic" dbEntityName="IMAGE_ASSET_CONTENT">
        <qualifier><![CDATA[contentType = "IMAGE"]]></qualifier>
        <obj-attribute name="height" type="java.lang.Integer"
db-attribute-path="HEIGHT"/>
        <obj-attribute name="width" type="java.lang.Integer"
db-attribute-path="WIDTH"/>
    </obj-entity>

Not sure if I need to provide you any more than that.  Cayenne accepts the
config fine, but when I create a new ImageAssetContent and save it, Cayenne
only saves to the IMAGE_ASSET_CONTENT  table:

2009-09-24 10:30:53,602 INFO [org.apache.cayenne.access.QueryLogger] -
<INSERT INTO IMAGE_ASSET_CONTENT (HEIGHT, ID, WIDTH) VALUES (?, ?, ?)>
2009-09-24 10:30:53,656 INFO [org.apache.cayenne.access.QueryLogger] -
<[batch bind: 1->HEIGHT:440, 2->ID:220, 3->WIDTH:495]>

I've confirmed that there is data in the object that should be getting saved
to the ASSET_CONTENT table but is not.

What's also interesting is that it is pulling an auto PK value (this is
running on a Derby DB for testing):

2009-09-24 10:30:53,258 INFO [org.apache.cayenne.access.QueryLogger] -
<SELECT NEXT_ID FROM AUTO_PK_SUPPORT WHERE TABLE_NAME = ? FOR UPDATE [bind:
1:'IMAGE_ASSET_CONTENT']>

Not so interesting that it's pulling one, but for IMAGE_ASSET_CONTENT?   I'd
assume it would be pulling for ASSET_CONTENT and reusing that ID in both the
parent and child tables.

Am I missing something really basic?

I've tested this on 3.0 M5 and M6 with same results.

Dave

Re: First time inheritance attempt

Posted by Michael Gentry <mg...@masslight.net>.
I faked vertical inheritance on a previous project.  It is a little
more manual/tedious, but works.  Mostly.  I had to manually manage the
relationships (such as when I created a new subclass instance, create
the superclass instance/relationship at the same time).  You could use
a listener/callback to automate that, though, so not too bad.  The
harder thing to remember was when doing a query you had to remember to
follow the relationships in they keypath yourself.  Java might see the
superclass getters/setters in the subclass, but the DB doesn't.  So
you have to always remember to do "superclass.whatever" when making an
expression that involves something off the superclass.


On Thu, Sep 24, 2009 at 2:20 PM, Dave Lamy <da...@gmail.com> wrote:
> Crap.  OK.  Nothing like an occasional reminder of what happens when you
> assume things.
>
> Thanks for the tip Michael-- I'll just use another method for now.
>
> Dave
>
> On Thu, Sep 24, 2009 at 1:18 PM, Michael Gentry <mg...@masslight.net>wrote:
>
>> I believe single-table and horizontal have been implemented, but I
>> don't think vertical has been implemented yet.  There is still an open
>> ticket for vertical inheritance:
>>
>> https://issues.apache.org/jira/browse/CAY-1090
>>
>>
>> On Thu, Sep 24, 2009 at 1:59 PM, Dave Lamy <da...@gmail.com> wrote:
>> > Yes, I'm attempting vertical multiple-table inheritance.  I was assuming
>> > functionality based upon this document:
>> >
>> > http://cayenne.apache.org/doc/inheritance-overview.html
>> >
>> > which had this section:
>> > Vertical (joined) inheritance
>> >
>> > This final approach requires one table per subclass plus one table for
>> the
>> > superclass. All attributes found in the superclass are stored in this
>> > additional table. This is particularly useful when you have lots of
>> common
>> > attributes or relations to other entities. Perhaps Person is subclassed
>> by
>> > Student, Teacher, Parent, AdminStaff, Visitor and Applicant. But all
>> these
>> > entities are allowed to borrow books from the library. Now, rather than
>> > creating 6 relationships between each of these tables to the Loan table,
>> you
>> > can create a single relationship between Person and Loan.
>> >
>> > Superclass: abstract or concrete
>> > Class designator column: required
>> > Primary key: in superclass. Copied into subclass to form the one-to-one
>> > join.
>> >
>> > Perhaps this is not yet implemented?  :-(
>> >
>> > Dave
>> >
>> >
>> > On Thu, Sep 24, 2009 at 12:46 PM, Michael Gentry <mgentry@masslight.net
>> >wrote:
>> >
>> >> You are trying to do multiple-table inheritance?
>> >>
>> >> Unless I'm mistaken, I don't believe that has been implemented yet.
>> >> Cayenne can do in-table inheritance using a discriminator column.
>> >>
>> >>
>> >> On Thu, Sep 24, 2009 at 1:10 PM, Dave Lamy <da...@gmail.com> wrote:
>> >> > Hey guys--
>> >> >
>> >> > I'm attempting to model some inheritance for the first time and it's
>> not
>> >> > working yet.  Here's my situation:
>> >> >
>> >> > My model is to have a non-abstract parent class->table and then
>> >> > subclass->tables like so:
>> >> >
>> >> > First I should doublecheck to make sure my mapping XML looks OK:
>> >> >
>> >> >    <db-entity name="ASSET_CONTENT">
>> >> >        ...
>> >> >        <db-attribute name="CONTENT_TYPE" type="VARCHAR" length="50"/>
>> >> >        <db-attribute name="ID" type="INTEGER" isPrimaryKey="true"
>> >> > isGenerated="true" isMandatory="true"/>
>> >> >        ...
>> >> >    </db-entity>
>> >> >    <db-entity name="IMAGE_ASSET_CONTENT">
>> >> >        <db-attribute name="HEIGHT" type="INTEGER"/>
>> >> >        <db-attribute name="ID" type="INTEGER" isPrimaryKey="true"
>> >> > isMandatory="true"/>
>> >> >        <db-attribute name="WIDTH" type="INTEGER"/>
>> >> >    </db-entity>
>> >> >    <obj-entity name="AssetContent"
>> >> > className="com.routeto1.asset.filesystem.AssetContent"
>> >> > lock-type="optimistic" dbEntityName="ASSET_CONTENT"
>> >> > superClassName="com.routeto1.data.impl.DynamicDataObject">
>> >> >        <obj-attribute name="contentType" type="java.lang.String"
>> >> > db-attribute-path="CONTENT_TYPE"/>
>> >> >         ...
>> >> >        <pre-persist method-name="prePersist"/>
>> >> >    </obj-entity>
>> >> >    <obj-entity name="ImageAssetContent" superEntityName="AssetContent"
>> >> > className="com.routeto1.asset.filesystem.ImageAssetContent"
>> >> > lock-type="optimistic" dbEntityName="IMAGE_ASSET_CONTENT">
>> >> >        <qualifier><![CDATA[contentType = "IMAGE"]]></qualifier>
>> >> >        <obj-attribute name="height" type="java.lang.Integer"
>> >> > db-attribute-path="HEIGHT"/>
>> >> >        <obj-attribute name="width" type="java.lang.Integer"
>> >> > db-attribute-path="WIDTH"/>
>> >> >    </obj-entity>
>> >> >
>> >> > Not sure if I need to provide you any more than that.  Cayenne accepts
>> >> the
>> >> > config fine, but when I create a new ImageAssetContent and save it,
>> >> Cayenne
>> >> > only saves to the IMAGE_ASSET_CONTENT  table:
>> >> >
>> >> > 2009-09-24 10:30:53,602 INFO [org.apache.cayenne.access.QueryLogger] -
>> >> > <INSERT INTO IMAGE_ASSET_CONTENT (HEIGHT, ID, WIDTH) VALUES (?, ?, ?)>
>> >> > 2009-09-24 10:30:53,656 INFO [org.apache.cayenne.access.QueryLogger] -
>> >> > <[batch bind: 1->HEIGHT:440, 2->ID:220, 3->WIDTH:495]>
>> >> >
>> >> > I've confirmed that there is data in the object that should be getting
>> >> saved
>> >> > to the ASSET_CONTENT table but is not.
>> >> >
>> >> > What's also interesting is that it is pulling an auto PK value (this
>> is
>> >> > running on a Derby DB for testing):
>> >> >
>> >> > 2009-09-24 10:30:53,258 INFO [org.apache.cayenne.access.QueryLogger] -
>> >> > <SELECT NEXT_ID FROM AUTO_PK_SUPPORT WHERE TABLE_NAME = ? FOR UPDATE
>> >> [bind:
>> >> > 1:'IMAGE_ASSET_CONTENT']>
>> >> >
>> >> > Not so interesting that it's pulling one, but for IMAGE_ASSET_CONTENT?
>> >> I'd
>> >> > assume it would be pulling for ASSET_CONTENT and reusing that ID in
>> both
>> >> the
>> >> > parent and child tables.
>> >> >
>> >> > Am I missing something really basic?
>> >> >
>> >> > I've tested this on 3.0 M5 and M6 with same results.
>> >> >
>> >> > Dave
>> >> >
>> >>
>> >
>>
>

Re: First time inheritance attempt

Posted by Dave Lamy <da...@gmail.com>.
Crap.  OK.  Nothing like an occasional reminder of what happens when you
assume things.

Thanks for the tip Michael-- I'll just use another method for now.

Dave

On Thu, Sep 24, 2009 at 1:18 PM, Michael Gentry <mg...@masslight.net>wrote:

> I believe single-table and horizontal have been implemented, but I
> don't think vertical has been implemented yet.  There is still an open
> ticket for vertical inheritance:
>
> https://issues.apache.org/jira/browse/CAY-1090
>
>
> On Thu, Sep 24, 2009 at 1:59 PM, Dave Lamy <da...@gmail.com> wrote:
> > Yes, I'm attempting vertical multiple-table inheritance.  I was assuming
> > functionality based upon this document:
> >
> > http://cayenne.apache.org/doc/inheritance-overview.html
> >
> > which had this section:
> > Vertical (joined) inheritance
> >
> > This final approach requires one table per subclass plus one table for
> the
> > superclass. All attributes found in the superclass are stored in this
> > additional table. This is particularly useful when you have lots of
> common
> > attributes or relations to other entities. Perhaps Person is subclassed
> by
> > Student, Teacher, Parent, AdminStaff, Visitor and Applicant. But all
> these
> > entities are allowed to borrow books from the library. Now, rather than
> > creating 6 relationships between each of these tables to the Loan table,
> you
> > can create a single relationship between Person and Loan.
> >
> > Superclass: abstract or concrete
> > Class designator column: required
> > Primary key: in superclass. Copied into subclass to form the one-to-one
> > join.
> >
> > Perhaps this is not yet implemented?  :-(
> >
> > Dave
> >
> >
> > On Thu, Sep 24, 2009 at 12:46 PM, Michael Gentry <mgentry@masslight.net
> >wrote:
> >
> >> You are trying to do multiple-table inheritance?
> >>
> >> Unless I'm mistaken, I don't believe that has been implemented yet.
> >> Cayenne can do in-table inheritance using a discriminator column.
> >>
> >>
> >> On Thu, Sep 24, 2009 at 1:10 PM, Dave Lamy <da...@gmail.com> wrote:
> >> > Hey guys--
> >> >
> >> > I'm attempting to model some inheritance for the first time and it's
> not
> >> > working yet.  Here's my situation:
> >> >
> >> > My model is to have a non-abstract parent class->table and then
> >> > subclass->tables like so:
> >> >
> >> > First I should doublecheck to make sure my mapping XML looks OK:
> >> >
> >> >    <db-entity name="ASSET_CONTENT">
> >> >        ...
> >> >        <db-attribute name="CONTENT_TYPE" type="VARCHAR" length="50"/>
> >> >        <db-attribute name="ID" type="INTEGER" isPrimaryKey="true"
> >> > isGenerated="true" isMandatory="true"/>
> >> >        ...
> >> >    </db-entity>
> >> >    <db-entity name="IMAGE_ASSET_CONTENT">
> >> >        <db-attribute name="HEIGHT" type="INTEGER"/>
> >> >        <db-attribute name="ID" type="INTEGER" isPrimaryKey="true"
> >> > isMandatory="true"/>
> >> >        <db-attribute name="WIDTH" type="INTEGER"/>
> >> >    </db-entity>
> >> >    <obj-entity name="AssetContent"
> >> > className="com.routeto1.asset.filesystem.AssetContent"
> >> > lock-type="optimistic" dbEntityName="ASSET_CONTENT"
> >> > superClassName="com.routeto1.data.impl.DynamicDataObject">
> >> >        <obj-attribute name="contentType" type="java.lang.String"
> >> > db-attribute-path="CONTENT_TYPE"/>
> >> >         ...
> >> >        <pre-persist method-name="prePersist"/>
> >> >    </obj-entity>
> >> >    <obj-entity name="ImageAssetContent" superEntityName="AssetContent"
> >> > className="com.routeto1.asset.filesystem.ImageAssetContent"
> >> > lock-type="optimistic" dbEntityName="IMAGE_ASSET_CONTENT">
> >> >        <qualifier><![CDATA[contentType = "IMAGE"]]></qualifier>
> >> >        <obj-attribute name="height" type="java.lang.Integer"
> >> > db-attribute-path="HEIGHT"/>
> >> >        <obj-attribute name="width" type="java.lang.Integer"
> >> > db-attribute-path="WIDTH"/>
> >> >    </obj-entity>
> >> >
> >> > Not sure if I need to provide you any more than that.  Cayenne accepts
> >> the
> >> > config fine, but when I create a new ImageAssetContent and save it,
> >> Cayenne
> >> > only saves to the IMAGE_ASSET_CONTENT  table:
> >> >
> >> > 2009-09-24 10:30:53,602 INFO [org.apache.cayenne.access.QueryLogger] -
> >> > <INSERT INTO IMAGE_ASSET_CONTENT (HEIGHT, ID, WIDTH) VALUES (?, ?, ?)>
> >> > 2009-09-24 10:30:53,656 INFO [org.apache.cayenne.access.QueryLogger] -
> >> > <[batch bind: 1->HEIGHT:440, 2->ID:220, 3->WIDTH:495]>
> >> >
> >> > I've confirmed that there is data in the object that should be getting
> >> saved
> >> > to the ASSET_CONTENT table but is not.
> >> >
> >> > What's also interesting is that it is pulling an auto PK value (this
> is
> >> > running on a Derby DB for testing):
> >> >
> >> > 2009-09-24 10:30:53,258 INFO [org.apache.cayenne.access.QueryLogger] -
> >> > <SELECT NEXT_ID FROM AUTO_PK_SUPPORT WHERE TABLE_NAME = ? FOR UPDATE
> >> [bind:
> >> > 1:'IMAGE_ASSET_CONTENT']>
> >> >
> >> > Not so interesting that it's pulling one, but for IMAGE_ASSET_CONTENT?
> >> I'd
> >> > assume it would be pulling for ASSET_CONTENT and reusing that ID in
> both
> >> the
> >> > parent and child tables.
> >> >
> >> > Am I missing something really basic?
> >> >
> >> > I've tested this on 3.0 M5 and M6 with same results.
> >> >
> >> > Dave
> >> >
> >>
> >
>

Re: First time inheritance attempt

Posted by Michael Gentry <mg...@masslight.net>.
I believe single-table and horizontal have been implemented, but I
don't think vertical has been implemented yet.  There is still an open
ticket for vertical inheritance:

https://issues.apache.org/jira/browse/CAY-1090


On Thu, Sep 24, 2009 at 1:59 PM, Dave Lamy <da...@gmail.com> wrote:
> Yes, I'm attempting vertical multiple-table inheritance.  I was assuming
> functionality based upon this document:
>
> http://cayenne.apache.org/doc/inheritance-overview.html
>
> which had this section:
> Vertical (joined) inheritance
>
> This final approach requires one table per subclass plus one table for the
> superclass. All attributes found in the superclass are stored in this
> additional table. This is particularly useful when you have lots of common
> attributes or relations to other entities. Perhaps Person is subclassed by
> Student, Teacher, Parent, AdminStaff, Visitor and Applicant. But all these
> entities are allowed to borrow books from the library. Now, rather than
> creating 6 relationships between each of these tables to the Loan table, you
> can create a single relationship between Person and Loan.
>
> Superclass: abstract or concrete
> Class designator column: required
> Primary key: in superclass. Copied into subclass to form the one-to-one
> join.
>
> Perhaps this is not yet implemented?  :-(
>
> Dave
>
>
> On Thu, Sep 24, 2009 at 12:46 PM, Michael Gentry <mg...@masslight.net>wrote:
>
>> You are trying to do multiple-table inheritance?
>>
>> Unless I'm mistaken, I don't believe that has been implemented yet.
>> Cayenne can do in-table inheritance using a discriminator column.
>>
>>
>> On Thu, Sep 24, 2009 at 1:10 PM, Dave Lamy <da...@gmail.com> wrote:
>> > Hey guys--
>> >
>> > I'm attempting to model some inheritance for the first time and it's not
>> > working yet.  Here's my situation:
>> >
>> > My model is to have a non-abstract parent class->table and then
>> > subclass->tables like so:
>> >
>> > First I should doublecheck to make sure my mapping XML looks OK:
>> >
>> >    <db-entity name="ASSET_CONTENT">
>> >        ...
>> >        <db-attribute name="CONTENT_TYPE" type="VARCHAR" length="50"/>
>> >        <db-attribute name="ID" type="INTEGER" isPrimaryKey="true"
>> > isGenerated="true" isMandatory="true"/>
>> >        ...
>> >    </db-entity>
>> >    <db-entity name="IMAGE_ASSET_CONTENT">
>> >        <db-attribute name="HEIGHT" type="INTEGER"/>
>> >        <db-attribute name="ID" type="INTEGER" isPrimaryKey="true"
>> > isMandatory="true"/>
>> >        <db-attribute name="WIDTH" type="INTEGER"/>
>> >    </db-entity>
>> >    <obj-entity name="AssetContent"
>> > className="com.routeto1.asset.filesystem.AssetContent"
>> > lock-type="optimistic" dbEntityName="ASSET_CONTENT"
>> > superClassName="com.routeto1.data.impl.DynamicDataObject">
>> >        <obj-attribute name="contentType" type="java.lang.String"
>> > db-attribute-path="CONTENT_TYPE"/>
>> >         ...
>> >        <pre-persist method-name="prePersist"/>
>> >    </obj-entity>
>> >    <obj-entity name="ImageAssetContent" superEntityName="AssetContent"
>> > className="com.routeto1.asset.filesystem.ImageAssetContent"
>> > lock-type="optimistic" dbEntityName="IMAGE_ASSET_CONTENT">
>> >        <qualifier><![CDATA[contentType = "IMAGE"]]></qualifier>
>> >        <obj-attribute name="height" type="java.lang.Integer"
>> > db-attribute-path="HEIGHT"/>
>> >        <obj-attribute name="width" type="java.lang.Integer"
>> > db-attribute-path="WIDTH"/>
>> >    </obj-entity>
>> >
>> > Not sure if I need to provide you any more than that.  Cayenne accepts
>> the
>> > config fine, but when I create a new ImageAssetContent and save it,
>> Cayenne
>> > only saves to the IMAGE_ASSET_CONTENT  table:
>> >
>> > 2009-09-24 10:30:53,602 INFO [org.apache.cayenne.access.QueryLogger] -
>> > <INSERT INTO IMAGE_ASSET_CONTENT (HEIGHT, ID, WIDTH) VALUES (?, ?, ?)>
>> > 2009-09-24 10:30:53,656 INFO [org.apache.cayenne.access.QueryLogger] -
>> > <[batch bind: 1->HEIGHT:440, 2->ID:220, 3->WIDTH:495]>
>> >
>> > I've confirmed that there is data in the object that should be getting
>> saved
>> > to the ASSET_CONTENT table but is not.
>> >
>> > What's also interesting is that it is pulling an auto PK value (this is
>> > running on a Derby DB for testing):
>> >
>> > 2009-09-24 10:30:53,258 INFO [org.apache.cayenne.access.QueryLogger] -
>> > <SELECT NEXT_ID FROM AUTO_PK_SUPPORT WHERE TABLE_NAME = ? FOR UPDATE
>> [bind:
>> > 1:'IMAGE_ASSET_CONTENT']>
>> >
>> > Not so interesting that it's pulling one, but for IMAGE_ASSET_CONTENT?
>> I'd
>> > assume it would be pulling for ASSET_CONTENT and reusing that ID in both
>> the
>> > parent and child tables.
>> >
>> > Am I missing something really basic?
>> >
>> > I've tested this on 3.0 M5 and M6 with same results.
>> >
>> > Dave
>> >
>>
>

Re: First time inheritance attempt

Posted by Dave Lamy <da...@gmail.com>.
Yes, I'm attempting vertical multiple-table inheritance.  I was assuming
functionality based upon this document:

http://cayenne.apache.org/doc/inheritance-overview.html

which had this section:
Vertical (joined) inheritance

This final approach requires one table per subclass plus one table for the
superclass. All attributes found in the superclass are stored in this
additional table. This is particularly useful when you have lots of common
attributes or relations to other entities. Perhaps Person is subclassed by
Student, Teacher, Parent, AdminStaff, Visitor and Applicant. But all these
entities are allowed to borrow books from the library. Now, rather than
creating 6 relationships between each of these tables to the Loan table, you
can create a single relationship between Person and Loan.

Superclass: abstract or concrete
Class designator column: required
Primary key: in superclass. Copied into subclass to form the one-to-one
join.

Perhaps this is not yet implemented?  :-(

Dave


On Thu, Sep 24, 2009 at 12:46 PM, Michael Gentry <mg...@masslight.net>wrote:

> You are trying to do multiple-table inheritance?
>
> Unless I'm mistaken, I don't believe that has been implemented yet.
> Cayenne can do in-table inheritance using a discriminator column.
>
>
> On Thu, Sep 24, 2009 at 1:10 PM, Dave Lamy <da...@gmail.com> wrote:
> > Hey guys--
> >
> > I'm attempting to model some inheritance for the first time and it's not
> > working yet.  Here's my situation:
> >
> > My model is to have a non-abstract parent class->table and then
> > subclass->tables like so:
> >
> > First I should doublecheck to make sure my mapping XML looks OK:
> >
> >    <db-entity name="ASSET_CONTENT">
> >        ...
> >        <db-attribute name="CONTENT_TYPE" type="VARCHAR" length="50"/>
> >        <db-attribute name="ID" type="INTEGER" isPrimaryKey="true"
> > isGenerated="true" isMandatory="true"/>
> >        ...
> >    </db-entity>
> >    <db-entity name="IMAGE_ASSET_CONTENT">
> >        <db-attribute name="HEIGHT" type="INTEGER"/>
> >        <db-attribute name="ID" type="INTEGER" isPrimaryKey="true"
> > isMandatory="true"/>
> >        <db-attribute name="WIDTH" type="INTEGER"/>
> >    </db-entity>
> >    <obj-entity name="AssetContent"
> > className="com.routeto1.asset.filesystem.AssetContent"
> > lock-type="optimistic" dbEntityName="ASSET_CONTENT"
> > superClassName="com.routeto1.data.impl.DynamicDataObject">
> >        <obj-attribute name="contentType" type="java.lang.String"
> > db-attribute-path="CONTENT_TYPE"/>
> >         ...
> >        <pre-persist method-name="prePersist"/>
> >    </obj-entity>
> >    <obj-entity name="ImageAssetContent" superEntityName="AssetContent"
> > className="com.routeto1.asset.filesystem.ImageAssetContent"
> > lock-type="optimistic" dbEntityName="IMAGE_ASSET_CONTENT">
> >        <qualifier><![CDATA[contentType = "IMAGE"]]></qualifier>
> >        <obj-attribute name="height" type="java.lang.Integer"
> > db-attribute-path="HEIGHT"/>
> >        <obj-attribute name="width" type="java.lang.Integer"
> > db-attribute-path="WIDTH"/>
> >    </obj-entity>
> >
> > Not sure if I need to provide you any more than that.  Cayenne accepts
> the
> > config fine, but when I create a new ImageAssetContent and save it,
> Cayenne
> > only saves to the IMAGE_ASSET_CONTENT  table:
> >
> > 2009-09-24 10:30:53,602 INFO [org.apache.cayenne.access.QueryLogger] -
> > <INSERT INTO IMAGE_ASSET_CONTENT (HEIGHT, ID, WIDTH) VALUES (?, ?, ?)>
> > 2009-09-24 10:30:53,656 INFO [org.apache.cayenne.access.QueryLogger] -
> > <[batch bind: 1->HEIGHT:440, 2->ID:220, 3->WIDTH:495]>
> >
> > I've confirmed that there is data in the object that should be getting
> saved
> > to the ASSET_CONTENT table but is not.
> >
> > What's also interesting is that it is pulling an auto PK value (this is
> > running on a Derby DB for testing):
> >
> > 2009-09-24 10:30:53,258 INFO [org.apache.cayenne.access.QueryLogger] -
> > <SELECT NEXT_ID FROM AUTO_PK_SUPPORT WHERE TABLE_NAME = ? FOR UPDATE
> [bind:
> > 1:'IMAGE_ASSET_CONTENT']>
> >
> > Not so interesting that it's pulling one, but for IMAGE_ASSET_CONTENT?
> I'd
> > assume it would be pulling for ASSET_CONTENT and reusing that ID in both
> the
> > parent and child tables.
> >
> > Am I missing something really basic?
> >
> > I've tested this on 3.0 M5 and M6 with same results.
> >
> > Dave
> >
>

Re: First time inheritance attempt

Posted by Michael Gentry <mg...@masslight.net>.
You are trying to do multiple-table inheritance?

Unless I'm mistaken, I don't believe that has been implemented yet.
Cayenne can do in-table inheritance using a discriminator column.


On Thu, Sep 24, 2009 at 1:10 PM, Dave Lamy <da...@gmail.com> wrote:
> Hey guys--
>
> I'm attempting to model some inheritance for the first time and it's not
> working yet.  Here's my situation:
>
> My model is to have a non-abstract parent class->table and then
> subclass->tables like so:
>
> First I should doublecheck to make sure my mapping XML looks OK:
>
>    <db-entity name="ASSET_CONTENT">
>        ...
>        <db-attribute name="CONTENT_TYPE" type="VARCHAR" length="50"/>
>        <db-attribute name="ID" type="INTEGER" isPrimaryKey="true"
> isGenerated="true" isMandatory="true"/>
>        ...
>    </db-entity>
>    <db-entity name="IMAGE_ASSET_CONTENT">
>        <db-attribute name="HEIGHT" type="INTEGER"/>
>        <db-attribute name="ID" type="INTEGER" isPrimaryKey="true"
> isMandatory="true"/>
>        <db-attribute name="WIDTH" type="INTEGER"/>
>    </db-entity>
>    <obj-entity name="AssetContent"
> className="com.routeto1.asset.filesystem.AssetContent"
> lock-type="optimistic" dbEntityName="ASSET_CONTENT"
> superClassName="com.routeto1.data.impl.DynamicDataObject">
>        <obj-attribute name="contentType" type="java.lang.String"
> db-attribute-path="CONTENT_TYPE"/>
>         ...
>        <pre-persist method-name="prePersist"/>
>    </obj-entity>
>    <obj-entity name="ImageAssetContent" superEntityName="AssetContent"
> className="com.routeto1.asset.filesystem.ImageAssetContent"
> lock-type="optimistic" dbEntityName="IMAGE_ASSET_CONTENT">
>        <qualifier><![CDATA[contentType = "IMAGE"]]></qualifier>
>        <obj-attribute name="height" type="java.lang.Integer"
> db-attribute-path="HEIGHT"/>
>        <obj-attribute name="width" type="java.lang.Integer"
> db-attribute-path="WIDTH"/>
>    </obj-entity>
>
> Not sure if I need to provide you any more than that.  Cayenne accepts the
> config fine, but when I create a new ImageAssetContent and save it, Cayenne
> only saves to the IMAGE_ASSET_CONTENT  table:
>
> 2009-09-24 10:30:53,602 INFO [org.apache.cayenne.access.QueryLogger] -
> <INSERT INTO IMAGE_ASSET_CONTENT (HEIGHT, ID, WIDTH) VALUES (?, ?, ?)>
> 2009-09-24 10:30:53,656 INFO [org.apache.cayenne.access.QueryLogger] -
> <[batch bind: 1->HEIGHT:440, 2->ID:220, 3->WIDTH:495]>
>
> I've confirmed that there is data in the object that should be getting saved
> to the ASSET_CONTENT table but is not.
>
> What's also interesting is that it is pulling an auto PK value (this is
> running on a Derby DB for testing):
>
> 2009-09-24 10:30:53,258 INFO [org.apache.cayenne.access.QueryLogger] -
> <SELECT NEXT_ID FROM AUTO_PK_SUPPORT WHERE TABLE_NAME = ? FOR UPDATE [bind:
> 1:'IMAGE_ASSET_CONTENT']>
>
> Not so interesting that it's pulling one, but for IMAGE_ASSET_CONTENT?   I'd
> assume it would be pulling for ASSET_CONTENT and reusing that ID in both the
> parent and child tables.
>
> Am I missing something really basic?
>
> I've tested this on 3.0 M5 and M6 with same results.
>
> Dave
>