unidirectional many-to-many

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

unidirectional many-to-many

Dierk König
I understand many-to-many is not supported, yet.

However, I'd like report that the error message for this currently
looks like (unidirectional many-to-many, i.e. Set visitiedEntries in User
class, no
corresponding property in TutorialEntry class)
----
Message: org.springframework.orm.hibernate3.HibernateSystemException:
not-null property references a null or transient value:
TutorialEntry._visitedEntriesBackref; nested exception is
org.hibernate.PropertyValueException: not-null property references a null or
transient value: TutorialEntry._visitedEntriesBackref
----
from the error message, it took me some to realize
that I was trying to use 'many-to-many' at all :-)

cheers
Mittie

Reply | Threaded
Open this post in threaded view
|

Re: unidirectional many-to-many

graemer
Excuse me if I'm being thick, but how can many-to-manys be
uni-directional? What you have there is a uni-directional one-to-many
with a circular dependency... i'm not sure this can be classified as a
uni-directional many-to-many.

What seems to be happening is that you are saving the TutorialEntry
class before it you have saved your User class, this means it has no
id assigned to it (ie its id is null) therefore the backRef (something
that is required in a uni-directional one-to-many) retrieves a null id
when trying to save your TutorialEntry, which is not allowed it seems

Graeme

On 02/03/06, Dierk Koenig <[hidden email]> wrote:

> I understand many-to-many is not supported, yet.
>
> However, I'd like report that the error message for this currently
> looks like (unidirectional many-to-many, i.e. Set visitiedEntries in User
> class, no
> corresponding property in TutorialEntry class)
> ----
> Message: org.springframework.orm.hibernate3.HibernateSystemException:
> not-null property references a null or transient value:
> TutorialEntry._visitedEntriesBackref; nested exception is
> org.hibernate.PropertyValueException: not-null property references a null or
> transient value: TutorialEntry._visitedEntriesBackref
> ----
> from the error message, it took me some to realize
> that I was trying to use 'many-to-many' at all :-)
>
> cheers
> Mittie
>
>
Reply | Threaded
Open this post in threaded view
|

RE: unidirectional many-to-many

Dierk König
*hehe* at least my mental model was many-to-many, but my implementation
was maybe not.

Users can visit TutorialEntries and the app needs to keep track of that to
suggest unvisited TutorialEntries for working on next.

So Users can visit many TuturialEntries.
Each TutorialEntry can be visitied my many Users.

I think the User should be the owner of this relation.

In relational terms I would introduce a 'Visit' relation table to
keep track of this.
In Object terms I would simply have a User keeping track visits in a
Set of TutorialEntries while TutorialEntry is totally unaware of the
visits.

What would be the Grails solution for this?

cheers
Mittie


> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]]On Behalf
> Of Graeme Rocher
> Sent: Donnerstag, 2. März 2006 10:00
> To: [hidden email]
> Subject: Re: [grails-dev] unidirectional many-to-many
>
>
> Excuse me if I'm being thick, but how can many-to-manys be
> uni-directional? What you have there is a uni-directional one-to-many
> with a circular dependency... i'm not sure this can be classified as a
> uni-directional many-to-many.
>
> What seems to be happening is that you are saving the TutorialEntry
> class before it you have saved your User class, this means it has no
> id assigned to it (ie its id is null) therefore the backRef (something
> that is required in a uni-directional one-to-many) retrieves a null id
> when trying to save your TutorialEntry, which is not allowed it seems
>
> Graeme
>
> On 02/03/06, Dierk Koenig <[hidden email]> wrote:
> > I understand many-to-many is not supported, yet.
> >
> > However, I'd like report that the error message for this currently
> > looks like (unidirectional many-to-many, i.e. Set
> visitiedEntries in User
> > class, no
> > corresponding property in TutorialEntry class)
> > ----
> > Message: org.springframework.orm.hibernate3.HibernateSystemException:
> > not-null property references a null or transient value:
> > TutorialEntry._visitedEntriesBackref; nested exception is
> > org.hibernate.PropertyValueException: not-null property
> references a null or
> > transient value: TutorialEntry._visitedEntriesBackref
> > ----
> > from the error message, it took me some to realize
> > that I was trying to use 'many-to-many' at all :-)
> >
> > cheers
> > Mittie
> >
> >

Reply | Threaded
Open this post in threaded view
|

Re: unidirectional many-to-many

graemer
On 02/03/06, Dierk Koenig <[hidden email]> wrote:

> *hehe* at least my mental model was many-to-many, but my implementation
> was maybe not.
>
> Users can visit TutorialEntries and the app needs to keep track of that to
> suggest unvisited TutorialEntries for working on next.
>
> So Users can visit many TuturialEntries.
> Each TutorialEntry can be visitied my many Users.
>
> I think the User should be the owner of this relation.
>
> In relational terms I would introduce a 'Visit' relation table to
> keep track of this.
> In Object terms I would simply have a User keeping track visits in a
> Set of TutorialEntries while TutorialEntry is totally unaware of the
> visits.
>
> What would be the Grails solution for this?

Right well its difficult to visualise as a paragraph of text (maybe we
do need that visualisation tool ;-) but if what i understand is
correct you have a 'User' with a property similar to the following:

@Property Set visits = new HashSet()

Mapped with something like this:

@Property relatesToMany = [ visits : TutorialEntry.class ]

Then what you have is a uni-directional one-to-many between User and
TutorialEntry..I guess the problem here is that if you delete a User
it has potential to delete your TutorialEntry objects, I'm not sure
that is what you want...

Also the way it appears is that many users can have the same
relationship with many TutorialEntries so yes it kind of is a
unidirectional many-to-many... and I'm not sure Grails has a solution
for this until we implement many-to-many relationships because what
you would need here is a JoinTable mapping..

And its an interesting point that maybe when we do get round to
implementing many-to-many we would need the abilitty to define the
'relatesToMany' property even if there is no 'actual' property so we
can support uni-directional many-to-manys.. something like:

@Property relatesToMany = [ users : User.class ]

in TutorialEntry, but there is no actual 'users' property.. This is doable.

As for your challenge, we're not going to support many-to-many
relationships until the 0.2 release so you have 2 options:

a) Map your domain model in Hibernate (probably not a great idea given
its an example of GORM)
b) Create a 'Visit" class in your object model like so:

class Visit {
       @Property Long id
       @Property Long version
       @Property User user
       @Property TutorialEntry entry
}

Then change your User class to use this one in its tutorialVisits
property instead..

Sorry I don't have a better solution!

Cheers
Graeme

>
> cheers
> Mittie
>
>
> > -----Original Message-----
> > From: [hidden email] [mailto:[hidden email]]On Behalf
> > Of Graeme Rocher
> > Sent: Donnerstag, 2. März 2006 10:00
> > To: [hidden email]
> > Subject: Re: [grails-dev] unidirectional many-to-many
> >
> >
> > Excuse me if I'm being thick, but how can many-to-manys be
> > uni-directional? What you have there is a uni-directional one-to-many
> > with a circular dependency... i'm not sure this can be classified as a
> > uni-directional many-to-many.
> >
> > What seems to be happening is that you are saving the TutorialEntry
> > class before it you have saved your User class, this means it has no
> > id assigned to it (ie its id is null) therefore the backRef (something
> > that is required in a uni-directional one-to-many) retrieves a null id
> > when trying to save your TutorialEntry, which is not allowed it seems
> >
> > Graeme
> >
> > On 02/03/06, Dierk Koenig <[hidden email]> wrote:
> > > I understand many-to-many is not supported, yet.
> > >
> > > However, I'd like report that the error message for this currently
> > > looks like (unidirectional many-to-many, i.e. Set
> > visitiedEntries in User
> > > class, no
> > > corresponding property in TutorialEntry class)
> > > ----
> > > Message: org.springframework.orm.hibernate3.HibernateSystemException:
> > > not-null property references a null or transient value:
> > > TutorialEntry._visitedEntriesBackref; nested exception is
> > > org.hibernate.PropertyValueException: not-null property
> > references a null or
> > > transient value: TutorialEntry._visitedEntriesBackref
> > > ----
> > > from the error message, it took me some to realize
> > > that I was trying to use 'many-to-many' at all :-)
> > >
> > > cheers
> > > Mittie
> > >
> > >
>
>