Quantcast

Problem with deep Inheritance

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Problem with deep Inheritance

Vincent_V
For example, I have the following domain class: Item, ItemWithPrice, ItemWithPriceAndImage

I execute the following:
new ItemWithPriceAndImage(name: "Pen", price: 10, imageURL: "....").save()
I look up the database and see that the new record have price = NULL

Why didn't the price get inserted?
The "class" column of the database is set to ItemWithPriceAndImage, but I think ItemWithPriceAndImage "is-a" ItemWithPrice, so every property should be persisted as well.

Moreover, what if I add another class called ItemWithPriceAndImageAndDescription?

class Item{
   String name
}

class ItemWithPrice extends Item{
   int price
}

class ItemWithPriceAndImage extends ItemWithPrice{
   String imageURL
}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Problem with deep Inheritance

ronriley
I also have this problem with 0.5 snapshot -  'grandchild' objects have grandparent attributes  persisted but not parent attributes.  Does anyone have a work-around?

DuyNguyen wrote
For example, I have the following domain class: Item, ItemWithPrice, ItemWithPriceAndImage

I execute the following:
new ItemWithPriceAndImage(name: "Pen", price: 10, imageURL: "....").save()
I look up the database and see that the new record have price = NULL

Why didn't the price get inserted?
The "class" column of the database is set to ItemWithPriceAndImage, but I think ItemWithPriceAndImage "is-a" ItemWithPrice, so every property should be persisted as well.

Moreover, what if I add another class called ItemWithPriceAndImageAndDescription?

class Item{
   String name
}

class ItemWithPrice extends Item{
   int price
}

class ItemWithPriceAndImage extends ItemWithPrice{
   String imageURL
}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Problem with deep Inheritance

kate rhodes
On 4/12/07, ronr <[hidden email]> wrote:
>
> I also have this problem with 0.5 snapshot -  'grandchild' objects have
> grandparent attributes  persisted but not parent attributes.  Does anyone
> have a work-around?


Oddly, I ran into this yesterday.
Workaround was just to move all the attributes of the child object up
to the parent and then have the grandchild extend the parent too.

It sucks but it works.


--
- kate = masukomi
http://weblog.masukomi.org/

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Problem with deep Inheritance

graemer
In reply to this post by ronriley
Please raise an issue in JIRA

Cheers

On 4/12/07, ronr <[hidden email]> wrote:

>
> I also have this problem with 0.5 snapshot -  'grandchild' objects have
> grandparent attributes  persisted but not parent attributes.  Does anyone
> have a work-around?
>
>
> DuyNguyen wrote:
> >
> > For example, I have the following domain class: Item, ItemWithPrice,
> > ItemWithPriceAndImage
> >
> > I execute the following:
> > new ItemWithPriceAndImage(name: "Pen", price: 10, imageURL: "....").save()
> > I look up the database and see that the new record have price = NULL
> >
> > Why didn't the price get inserted?
> > The "class" column of the database is set to ItemWithPriceAndImage, but I
> > think ItemWithPriceAndImage "is-a" ItemWithPrice, so every property should
> > be persisted as well.
> >
> > Moreover, what if I add another class called
> > ItemWithPriceAndImageAndDescription?
> >
> > class Item{
> >    String name
> > }
> >
> > class ItemWithPrice extends Item{
> >    int price
> > }
> >
> > class ItemWithPriceAndImage extends ItemWithPrice{
> >    String imageURL
> > }
> >
>
> --
> View this message in context: http://www.nabble.com/Problem-with-deep-Inheritance-tf3563362.html#a9957606
> Sent from the grails - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>


--
Graeme Rocher
Grails Project Lead
http://grails.org

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Problem with deep Inheritance

kate rhodes
On 4/12/07, Graeme Rocher <[hidden email]> wrote:
> Please raise an issue in JIRA

done:
http://jira.codehaus.org/browse/GRAILS-1042


--
- kate = masukomi
http://weblog.masukomi.org/

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Problem with deep Inheritance

Vincent_V
In reply to this post by graemer
Thanks for posting the JIRA entry.
I have also worked it around by moving the properties from the grandchild to the grandparent class as you've mentioned. It sucks big time because it breaks my database model.

I wonder if this is a problem with Hibernate or with GORM? I remembered working with things similar to this with Hibernate before, and it worked just fine.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Problem with deep Inheritance

graemer
It is going to be a GORM mapping problem

Cheers

On 4/13/07, DuyNguyen <[hidden email]> wrote:

>
> Thanks for posting the JIRA entry.
> I have also worked it around by moving the properties from the grandchild to
> the grandparent class as you've mentioned. It sucks big time because it
> breaks my database model.
>
> I wonder if this is a problem with Hibernate or with GORM? I remembered
> working with things similar to this with Hibernate before, and it worked
> just fine.
> --
> View this message in context: http://www.nabble.com/Problem-with-deep-Inheritance-tf3563362.html#a9973444
> Sent from the grails - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>


--
Graeme Rocher
Grails Project Lead
http://grails.org

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Another problem

Vincent_V
In reply to this post by Vincent_V
I ran into another problem. Don't know if this and the last one are connected. I might as well start another topic.

This time I have domain class Car inherit from domain class Vehicle

class Vehicle {
        def printMe(){
                println id
        }
}

class Car {
}

Now in CarController I have:
Car.get(params.id).printMe()

and the following exception pops:
groovy.lang.MissingMethodException: No signature of method: Car.printMe() is applicable for argument types: () values: {}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Another problem

james_027
hi,

you forgot the class Car extends Vehicle {

}

cheers,
james
DuyNguyen wrote
I ran into another problem. Don't know if this and the last one are connected. I might as well start another topic.

This time I have domain class Car inherit from domain class Vehicle

class Vehicle {
        def printMe(){
                println id
        }
}

class Car {
}

Now in CarController I have:
Car.get(params.id).printMe()

and the following exception pops:
groovy.lang.MissingMethodException: No signature of method: Car.printMe() is applicable for argument types: () values: {}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Another problem

Vincent_V
Sorry I forgot the extends statement

But the problem is: after I change the Car class to extends Vehicle, why do I receive a "null" at the console?
It means that the prinln id actually prints a null value, and id is null (???)
If I change the statement from println to executeQuery("from Vehicle where id = ?", id), I also receive a NullException for id property.
Loading...