Hibernate Error

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

Hibernate Error

Kerry Wilson-3
Just downloaded snapshot and I am getting a hibernate error on startup:

org.hibernate.MappingException: property mapping has wrong number of
columns: Team.relatesToOne type: object

For the following code:

class Team {
    @Property Long id
    @Property Long version

    @Property String name
    @Property String description
    @Property League league
    @Property User coach
   
    // Setup relational mappings
    def belongsTo = League
    def relatesToOne = [ coach : User ]
    def relatesToMany = [ players : User ]
   
    // Initialize
    Set players = new HashSet()                    
   
    String toString() { "${this.class.name} :  $id" }
}

What is wrong?

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

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Hibernate Error

graemer
'relatesToOne' is not a valid setting. Grails doesn't need this
because it has static types (unlike ruby).. just do:

@Property User coach

Rgds
Graeme

On 6/23/06, Kerry Wilson <[hidden email]> wrote:

> Just downloaded snapshot and I am getting a hibernate error on startup:
>
> org.hibernate.MappingException: property mapping has wrong number of
> columns: Team.relatesToOne type: object
>
> For the following code:
>
> class Team {
>     @Property Long id
>     @Property Long version
>
>     @Property String name
>     @Property String description
>     @Property League league
>     @Property User coach
>
>     // Setup relational mappings
>     def belongsTo = League
>     def relatesToOne = [ coach : User ]
>     def relatesToMany = [ players : User ]
>
>     // Initialize
>     Set players = new HashSet()
>
>     String toString() { "${this.class.name} :  $id" }
> }
>
> What is wrong?
>
> ---------------------------------------------------------------------
> 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: Hibernate Error

Kerry Wilson-3
Of course, I guess I just made that up...

Anyways, how do you represent the relationship between league and coach?

Coach is a User object but User's can also be Players

So League has commissioner that is a user
League has teams that have players which are users

Is it enough just to declare a property coach as a User?



Graeme Rocher wrote:

> 'relatesToOne' is not a valid setting. Grails doesn't need this
> because it has static types (unlike ruby).. just do:
>
> @Property User coach
>
> Rgds
> Graeme
>
> On 6/23/06, Kerry Wilson <[hidden email]> wrote:
>
>> Just downloaded snapshot and I am getting a hibernate error on startup:
>>
>> org.hibernate.MappingException: property mapping has wrong number of
>> columns: Team.relatesToOne type: object
>>
>> For the following code:
>>
>> class Team {
>>     @Property Long id
>>     @Property Long version
>>
>>     @Property String name
>>     @Property String description
>>     @Property League league
>>     @Property User coach
>>
>>     // Setup relational mappings
>>     def belongsTo = League
>>     def relatesToOne = [ coach : User ]
>>     def relatesToMany = [ players : User ]
>>
>>     // Initialize
>>     Set players = new HashSet()
>>
>>     String toString() { "${this.class.name} :  $id" }
>> }
>>
>> What is wrong?
>>
>> ---------------------------------------------------------------------
>> 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: Hibernate Error

Dierk König
 --------           --------          --------
| League |         | Team   |        | Player |
 --------           --------          --------
|        | <------ | league | <----- | team   |
 --------           --------  <-+     --------
                                |
                                |     --------
                                |    | Coach  |
                                |     --------
                                +--- | team   |
                                      --------
assuming a coaches and players only
belong to one team...

That's all plain properties that make up the
unidirectional relation. With dynamic finders
there is no need for any sophisticated
structure.

cheers
Mittie

> -----Original Message-----
> From: Kerry Wilson [mailto:[hidden email]]
> Sent: Freitag, 23. Juni 2006 14:31
> To: [hidden email]
> Subject: Re: [grails-user] Hibernate Error
>
>
> Of course, I guess I just made that up...
>
> Anyways, how do you represent the relationship between league and coach?
>
> Coach is a User object but User's can also be Players
>
> So League has commissioner that is a user
> League has teams that have players which are users
>
> Is it enough just to declare a property coach as a User?
>
>
>
> Graeme Rocher wrote:
>
> > 'relatesToOne' is not a valid setting. Grails doesn't need this
> > because it has static types (unlike ruby).. just do:
> >
> > @Property User coach
> >
> > Rgds
> > Graeme
> >
> > On 6/23/06, Kerry Wilson <[hidden email]> wrote:
> >
> >> Just downloaded snapshot and I am getting a hibernate error on startup:
> >>
> >> org.hibernate.MappingException: property mapping has wrong number of
> >> columns: Team.relatesToOne type: object
> >>
> >> For the following code:
> >>
> >> class Team {
> >>     @Property Long id
> >>     @Property Long version
> >>
> >>     @Property String name
> >>     @Property String description
> >>     @Property League league
> >>     @Property User coach
> >>
> >>     // Setup relational mappings
> >>     def belongsTo = League
> >>     def relatesToOne = [ coach : User ]
> >>     def relatesToMany = [ players : User ]
> >>
> >>     // Initialize
> >>     Set players = new HashSet()
> >>
> >>     String toString() { "${this.class.name} :  $id" }
> >> }
> >>
> >> What is wrong?
> >>
> >> ---------------------------------------------------------------------
> >> 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

Reply | Threaded
Open this post in threaded view
|

Re: Hibernate Error

Kerry Wilson-3
Actually, now that I think of it, Players can belong to more that 1 team
(in a different league), but, Grails doesn't do M : M yet does it?

Dierk Koenig wrote:

>  --------           --------          --------
> | League |         | Team   |        | Player |
>  --------           --------          --------
> |        | <------ | league | <----- | team   |
>  --------           --------  <-+     --------
>                                 |
>                                 |     --------
>                                 |    | Coach  |
>                                 |     --------
>                                 +--- | team   |
>                                       --------
> assuming a coaches and players only
> belong to one team...
>
> That's all plain properties that make up the
> unidirectional relation. With dynamic finders
> there is no need for any sophisticated
> structure.
>
> cheers
> Mittie
>
>  
>> -----Original Message-----
>> From: Kerry Wilson [mailto:[hidden email]]
>> Sent: Freitag, 23. Juni 2006 14:31
>> To: [hidden email]
>> Subject: Re: [grails-user] Hibernate Error
>>
>>
>> Of course, I guess I just made that up...
>>
>> Anyways, how do you represent the relationship between league and coach?
>>
>> Coach is a User object but User's can also be Players
>>
>> So League has commissioner that is a user
>> League has teams that have players which are users
>>
>> Is it enough just to declare a property coach as a User?
>>
>>
>>
>> Graeme Rocher wrote:
>>
>>    
>>> 'relatesToOne' is not a valid setting. Grails doesn't need this
>>> because it has static types (unlike ruby).. just do:
>>>
>>> @Property User coach
>>>
>>> Rgds
>>> Graeme
>>>
>>> On 6/23/06, Kerry Wilson <[hidden email]> wrote:
>>>
>>>      
>>>> Just downloaded snapshot and I am getting a hibernate error on startup:
>>>>
>>>> org.hibernate.MappingException: property mapping has wrong number of
>>>> columns: Team.relatesToOne type: object
>>>>
>>>> For the following code:
>>>>
>>>> class Team {
>>>>     @Property Long id
>>>>     @Property Long version
>>>>
>>>>     @Property String name
>>>>     @Property String description
>>>>     @Property League league
>>>>     @Property User coach
>>>>
>>>>     // Setup relational mappings
>>>>     def belongsTo = League
>>>>     def relatesToOne = [ coach : User ]
>>>>     def relatesToMany = [ players : User ]
>>>>
>>>>     // Initialize
>>>>     Set players = new HashSet()
>>>>
>>>>     String toString() { "${this.class.name} :  $id" }
>>>> }
>>>>
>>>> What is wrong?
>>>>
>>>> ---------------------------------------------------------------------
>>>> 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
>
>
>  

--
Kerry Wilson
Lead Developer
Williams Web
[hidden email] | 423.485.4747


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

    http://xircles.codehaus.org/manage_email

kwilson.vcf (292 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Hibernate Error

graemer
In reply to this post by Dierk König
I would probably use inheritance for the User someting like:

class User {
 ... // user propertys
}

class Coach extends User {
...
}

class Player extends User {
...
}

Then have:

class League {
     def relatesToMany = [players:Player]
     Coach coach
     Set players
}

Btw the above assumes you are using 0.2 snapshots

Cheers
Graeme

On 6/23/06, Dierk Koenig <[hidden email]> wrote:

>  --------           --------          --------
> | League |         | Team   |        | Player |
>  --------           --------          --------
> |        | <------ | league | <----- | team   |
>  --------           --------  <-+     --------
>                                 |
>                                 |     --------
>                                 |    | Coach  |
>                                 |     --------
>                                 +--- | team   |
>                                       --------
> assuming a coaches and players only
> belong to one team...
>
> That's all plain properties that make up the
> unidirectional relation. With dynamic finders
> there is no need for any sophisticated
> structure.
>
> cheers
> Mittie
>
> > -----Original Message-----
> > From: Kerry Wilson [mailto:[hidden email]]
> > Sent: Freitag, 23. Juni 2006 14:31
> > To: [hidden email]
> > Subject: Re: [grails-user] Hibernate Error
> >
> >
> > Of course, I guess I just made that up...
> >
> > Anyways, how do you represent the relationship between league and coach?
> >
> > Coach is a User object but User's can also be Players
> >
> > So League has commissioner that is a user
> > League has teams that have players which are users
> >
> > Is it enough just to declare a property coach as a User?
> >
> >
> >
> > Graeme Rocher wrote:
> >
> > > 'relatesToOne' is not a valid setting. Grails doesn't need this
> > > because it has static types (unlike ruby).. just do:
> > >
> > > @Property User coach
> > >
> > > Rgds
> > > Graeme
> > >
> > > On 6/23/06, Kerry Wilson <[hidden email]> wrote:
> > >
> > >> Just downloaded snapshot and I am getting a hibernate error on startup:
> > >>
> > >> org.hibernate.MappingException: property mapping has wrong number of
> > >> columns: Team.relatesToOne type: object
> > >>
> > >> For the following code:
> > >>
> > >> class Team {
> > >>     @Property Long id
> > >>     @Property Long version
> > >>
> > >>     @Property String name
> > >>     @Property String description
> > >>     @Property League league
> > >>     @Property User coach
> > >>
> > >>     // Setup relational mappings
> > >>     def belongsTo = League
> > >>     def relatesToOne = [ coach : User ]
> > >>     def relatesToMany = [ players : User ]
> > >>
> > >>     // Initialize
> > >>     Set players = new HashSet()
> > >>
> > >>     String toString() { "${this.class.name} :  $id" }
> > >> }
> > >>
> > >> What is wrong?
> > >>
> > >> ---------------------------------------------------------------------
> > >> 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
>
>

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

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Hibernate Error

graemer
In reply to this post by Kerry Wilson-3
On 6/23/06, Kerry Wilson <[hidden email]> wrote:
> Actually, now that I think of it, Players can belong to more that 1 team
> (in a different league), but, Grails doesn't do M : M yet does it?

No but you can use a mapping class which is essentially the same thing:

class Player { ... }
class Team { .. }

class TeamMembership {
       .....
       Player player
       Team team
}

Then of course the player can have multiple teams, you just need to
create new TeamMembership instances. Finding the teams for player can
be achieved with GPath:

List teams = TeamMembership.findAllByPlayer(player).team

Or all the players for a team:

List players = TeamMembership.findAllByTeam(team).player

Cheers
Graeme

>
> Dierk Koenig wrote:
> >  --------           --------          --------
> > | League |         | Team   |        | Player |
> >  --------           --------          --------
> > |        | <------ | league | <----- | team   |
> >  --------           --------  <-+     --------
> >                                 |
> >                                 |     --------
> >                                 |    | Coach  |
> >                                 |     --------
> >                                 +--- | team   |
> >                                       --------
> > assuming a coaches and players only
> > belong to one team...
> >
> > That's all plain properties that make up the
> > unidirectional relation. With dynamic finders
> > there is no need for any sophisticated
> > structure.
> >
> > cheers
> > Mittie
> >
> >
> >> -----Original Message-----
> >> From: Kerry Wilson [mailto:[hidden email]]
> >> Sent: Freitag, 23. Juni 2006 14:31
> >> To: [hidden email]
> >> Subject: Re: [grails-user] Hibernate Error
> >>
> >>
> >> Of course, I guess I just made that up...
> >>
> >> Anyways, how do you represent the relationship between league and coach?
> >>
> >> Coach is a User object but User's can also be Players
> >>
> >> So League has commissioner that is a user
> >> League has teams that have players which are users
> >>
> >> Is it enough just to declare a property coach as a User?
> >>
> >>
> >>
> >> Graeme Rocher wrote:
> >>
> >>
> >>> 'relatesToOne' is not a valid setting. Grails doesn't need this
> >>> because it has static types (unlike ruby).. just do:
> >>>
> >>> @Property User coach
> >>>
> >>> Rgds
> >>> Graeme
> >>>
> >>> On 6/23/06, Kerry Wilson <[hidden email]> wrote:
> >>>
> >>>
> >>>> Just downloaded snapshot and I am getting a hibernate error on startup:
> >>>>
> >>>> org.hibernate.MappingException: property mapping has wrong number of
> >>>> columns: Team.relatesToOne type: object
> >>>>
> >>>> For the following code:
> >>>>
> >>>> class Team {
> >>>>     @Property Long id
> >>>>     @Property Long version
> >>>>
> >>>>     @Property String name
> >>>>     @Property String description
> >>>>     @Property League league
> >>>>     @Property User coach
> >>>>
> >>>>     // Setup relational mappings
> >>>>     def belongsTo = League
> >>>>     def relatesToOne = [ coach : User ]
> >>>>     def relatesToMany = [ players : User ]
> >>>>
> >>>>     // Initialize
> >>>>     Set players = new HashSet()
> >>>>
> >>>>     String toString() { "${this.class.name} :  $id" }
> >>>> }
> >>>>
> >>>> What is wrong?
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> 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
> >
> >
> >
>
>
> --
> Kerry Wilson
> Lead Developer
> Williams Web
> [hidden email] | 423.485.4747
>
>
>
> ---------------------------------------------------------------------
> 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