Re: Re: [user] Relational Mapping Problem (the sequel to "duplicate backref" issue)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Re: [user] Relational Mapping Problem (the sequel to "duplicate backref" issue)

Beaur, Remi
I was working on my side to find a solution to this problem but I've
just seen that we
have come to the same conclusion about it : the current implementation
of inheritance
was wrong.

However I was working on a different solution that would not remove
table-per-subclass inheritance. Your solution with table-per-hierarchy
should work
well but there will be a big limitation : persistent attributes may not
have NOT NULL
constraints :
http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#inheritance

I believe the problem could be solved in a different way. In fact, it
seems to me you
should map all properties referencing instances not to the ID in the
subclasses tables
but rather to the ID of the inherited class table. Furthermore all
instances should be
referenced in the upper class table, so it should be possible to list
them directly with
the scaffolded list view (associated with the "parent" class).

Another solution could be to use table-per-concrete-class. By now, I
don't succeed in
making my parent class abstract (in order to avoid it being instanciated
as its
subclasses).

May be I passed over some problems (or I may have misunderstood your
coding).
Don't hesitate to correct my mistakes!

Cheers
Rémi

Graeme Rocher a écrit :

> We'll do our best add support for this, but we do have to finalize the
> plug-in architecture and get out 0.2 shortly so i'm not sure on the
> ETA at this point.
>
> If you need it right away I suggest using EJB3 entities and mapping
> with hibernate annotations instead which will allow you to do what you
> want to achieve now
>
> Cheers
> Graeme
>
> On 6/7/06, Beaur, Remi <[hidden email]> wrote:
>  
>> Is there any hope that combining inheritance and one-to-many relations
>> could work?
>>
>> As I said previously it's an important part of my project and I really
>> can't do it another
>> way. I post an issue on Jira :
>> http://jira.codehaus.org/browse/GRAILS-164 (I made
>> a mistake when registering it since I put it in Controllers rather
>>    
> than
>  
>> in Persistence
>> where it should be, because of my scrolling wheel).
>>
>> Rémi Béaur a écrit :
>>    
>>> I will look into this and create another issue on Jira.
>>>
>>> I already simplify my model but inheritance is a fundamental part of
>>> my project.
>>> Further simplifications will be possible when many-to-many relations
>>> are available.
>>>
>>> Thanks for your great work,
>>> Rémi
>>>
>>> Graeme Rocher a écrit :
>>>      
>>>> Create a new issue and attached your domain model to it and it will
>>>> eventually be resolved.
>>>>
>>>> I know that its not nice when the ORM solution effects the way you
>>>> want to model your domain, but this tends to always occur with
>>>> whatever ORM solutions you are using (hibernate, toplink,
>>>>        
> activerecord
>  
>>>> etc.) May advice would be to simplify you domain model.
>>>>
>>>> Do you REALLY need inheritence?
>>>>
>>>> Regards
>>>> Graeme
>>>>
>>>> On 5/23/06, Beaur, Remi <[hidden email]> wrote:
>>>>
>>>>        
>>>>> Hello,
>>>>>
>>>>> There has been a resolution concerning the "duplicate backref"
>>>>>          
> issue
>  
>>>> on
>>>>
>>>>        
>>>>> Jira :
>>>>> http://jira.codehaus.org/browse/GRAILS-138 .
>>>>> The previous error has been treated but now I encounter a new one.
>>>>>
>>>>> I have a domain named ProjectObjectRelation being the "one" part
>>>>>          
> of 2
>  
>>>>> one-to-many relations
>>>>> with domains named SCObject and Project. The property of
>>>>> ProjectObjectRelation that
>>>>> represents the mapping with Project is ProjectRelations.
>>>>>
>>>>> SCObject has multiple sub-classes that extend it (Picture,
>>>>>          
> Video,...).
>  
>>>>> The error seems to come
>>>>> from here since it disappears when I keep only one sub-class.
>>>>>
>>>>> I get the following error :
>>>>>
>>>>> [groovy] org.springframework.beans.factory.BeanCreationException:
>>>>> Error creating bean with name 'sessionFactory' defined in resource
>>>>> loaded through InputStream:
>>>>> Initialization of bean failed; nested exception is
>>>>> org.hibernate.MappingException:
>>>>> Repeated column in mapping for entity: ProjectObjectRelation
>>>>>          
> column:
>  
>>>>> PROJECTRELATIONS_ID (should be mapped with insert="false"
>>>>>
>>>>>          
>>>> update="false")
>>>>
>>>>        
>>>>> Any idea?
>>>>> Thanks,
>>>>> Rémi
>>>>>
>>>>>
>>>>>          
>>>>        
> ---------------------------------------------------------------------
>  
>>>> To unsubscribe, e-mail: [hidden email]
>>>> For additional commands, e-mail: [hidden email]
>>>>
>>>>
>>>>
>>>>        
>>>      
>> ---------------------------------------------------------------------
>> To unsubscribe from this list please visit:
>>
>>     http://xircles.codehaus.org/manage_email
>>
>>
>>    
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>
>  

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

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Re: [user] Relational Mapping Problem (the sequel to "duplicate backref" issue)

graemer
On 6/12/06, Beaur, Remi <[hidden email]> wrote:

> I was working on my side to find a solution to this problem but I've
> just seen that we
> have come to the same conclusion about it : the current implementation
> of inheritance
> was wrong.
>
> However I was working on a different solution that would not remove
> table-per-subclass inheritance. Your solution with table-per-hierarchy
> should work
> well but there will be a big limitation : persistent attributes may not
> have NOT NULL
> constraints :
> http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#inheritance

Yes but that only applies to the sub-classes, the parent class can
have NOT NULL constraints.. only a big issue if you make it one IMO
and you can still have NOT NULL constraints on your domain model using
Grails validation constraints

>
> I believe the problem could be solved in a different way. In fact, it
> seems to me you
> should map all properties referencing instances not to the ID in the
> subclasses tables
> but rather to the ID of the inherited class table. Furthermore all
> instances should be
This is easier said than done, the ORM part of Grails is complicated
no getting round it there are all sorts of corner cases and
permutations that could occur in different domain models. It would be
difficult to come up with a one solution fits all scenario (which is
why hibernate XML gets complicated when you use inheritance)

If you want to delve into the code and have a go at this feel free :-)

> referenced in the upper class table, so it should be possible to list
> them directly with
> the scaffolded list view (associated with the "parent" class).
>
> Another solution could be to use table-per-concrete-class. By now, I
> don't succeed in
> making my parent class abstract (in order to avoid it being instanciated
> as its
> subclasses).
You can still do table-per-concrete class by making the parent
abstract, but clearly this is likely to result in similar issues that
you have now.

Thanks for the suggestions, however i believe we have a good enough
compromise at the moment with table-per-heirarchy and it also allows
polymorphic queries which table-per-subclass does not.

No ORM system allows total freedom in designing your domain model, and
if you want this total freedom it comes at a cost of lots of
configuration which has never been the goal of GORM.

Graeme

>
> May be I passed over some problems (or I may have misunderstood your
> coding).
> Don't hesitate to correct my mistakes!
>
> Cheers
> Rémi
>
> Graeme Rocher a écrit :
> > We'll do our best add support for this, but we do have to finalize the
> > plug-in architecture and get out 0.2 shortly so i'm not sure on the
> > ETA at this point.
> >
> > If you need it right away I suggest using EJB3 entities and mapping
> > with hibernate annotations instead which will allow you to do what you
> > want to achieve now
> >
> > Cheers
> > Graeme
> >
> > On 6/7/06, Beaur, Remi <[hidden email]> wrote:
> >
> >> Is there any hope that combining inheritance and one-to-many relations
> >> could work?
> >>
> >> As I said previously it's an important part of my project and I really
> >> can't do it another
> >> way. I post an issue on Jira :
> >> http://jira.codehaus.org/browse/GRAILS-164 (I made
> >> a mistake when registering it since I put it in Controllers rather
> >>
> > than
> >
> >> in Persistence
> >> where it should be, because of my scrolling wheel).
> >>
> >> Rémi Béaur a écrit :
> >>
> >>> I will look into this and create another issue on Jira.
> >>>
> >>> I already simplify my model but inheritance is a fundamental part of
> >>> my project.
> >>> Further simplifications will be possible when many-to-many relations
> >>> are available.
> >>>
> >>> Thanks for your great work,
> >>> Rémi
> >>>
> >>> Graeme Rocher a écrit :
> >>>
> >>>> Create a new issue and attached your domain model to it and it will
> >>>> eventually be resolved.
> >>>>
> >>>> I know that its not nice when the ORM solution effects the way you
> >>>> want to model your domain, but this tends to always occur with
> >>>> whatever ORM solutions you are using (hibernate, toplink,
> >>>>
> > activerecord
> >
> >>>> etc.) May advice would be to simplify you domain model.
> >>>>
> >>>> Do you REALLY need inheritence?
> >>>>
> >>>> Regards
> >>>> Graeme
> >>>>
> >>>> On 5/23/06, Beaur, Remi <[hidden email]> wrote:
> >>>>
> >>>>
> >>>>> Hello,
> >>>>>
> >>>>> There has been a resolution concerning the "duplicate backref"
> >>>>>
> > issue
> >
> >>>> on
> >>>>
> >>>>
> >>>>> Jira :
> >>>>> http://jira.codehaus.org/browse/GRAILS-138 .
> >>>>> The previous error has been treated but now I encounter a new one.
> >>>>>
> >>>>> I have a domain named ProjectObjectRelation being the "one" part
> >>>>>
> > of 2
> >
> >>>>> one-to-many relations
> >>>>> with domains named SCObject and Project. The property of
> >>>>> ProjectObjectRelation that
> >>>>> represents the mapping with Project is ProjectRelations.
> >>>>>
> >>>>> SCObject has multiple sub-classes that extend it (Picture,
> >>>>>
> > Video,...).
> >
> >>>>> The error seems to come
> >>>>> from here since it disappears when I keep only one sub-class.
> >>>>>
> >>>>> I get the following error :
> >>>>>
> >>>>> [groovy] org.springframework.beans.factory.BeanCreationException:
> >>>>> Error creating bean with name 'sessionFactory' defined in resource
> >>>>> loaded through InputStream:
> >>>>> Initialization of bean failed; nested exception is
> >>>>> org.hibernate.MappingException:
> >>>>> Repeated column in mapping for entity: ProjectObjectRelation
> >>>>>
> > column:
> >
> >>>>> PROJECTRELATIONS_ID (should be mapped with insert="false"
> >>>>>
> >>>>>
> >>>> update="false")
> >>>>
> >>>>
> >>>>> Any idea?
> >>>>> Thanks,
> >>>>> Rémi
> >>>>>
> >>>>>
> >>>>>
> >>>>
> > ---------------------------------------------------------------------
> >
> >>>> To unsubscribe, e-mail: [hidden email]
> >>>> For additional commands, e-mail: [hidden email]
> >>>>
> >>>>
> >>>>
> >>>>
> >>>
> >> ---------------------------------------------------------------------
> >> To unsubscribe from this list please visit:
> >>
> >>     http://xircles.codehaus.org/manage_email
> >>
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe from this list please visit:
> >
> >     http://xircles.codehaus.org/manage_email
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>

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

    http://xircles.codehaus.org/manage_email