relatesToMany

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

relatesToMany

Jonathan Carlson
I just realized that my earlier "solution" of changing @Property to Map for relatesToMany doesn't actually work because the many field never gets populated.

I'm baffled.  Below I'm using the exact example from the GORM page but "@Property relatesToMany=[ books:Book.class]" throws the Hibernate error below.  This must be happening to others too. Can someone else try this?  It happens to me with both JDK 1.4 and 1.5.

   [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: property mapping has wrong number of columns: Author.relatesToMany type: object
   [groovy] org.hibernate.MappingException: property mapping has wrong number of columns: Author.relatesToMany type: object
   [groovy]     at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:396)
   [groovy]     at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
   [groovy]     at org.hibernate.cfg.Configuration.validate(Configuration.java:984)
   [groovy]     at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1169)
   [groovy]     at org.codehaus.groovy.grails.orm.hibernate.cfg.DefaultGrailsDomainConfiguration.buildSessionFactory(DefaultGrailsDomainConfiguration.java:93)
   [groovy]     at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:800)
   [groovy]     at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:726)
   [groovy]     at org.codehaus.groovy.grails.orm.hibernate.ConfigurableLocalSessionFactoryBean.afterPropertiesSet(ConfigurableLocalSessionFactoryBean.java:92)
   [groovy]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1059)
   [groovy]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:363)
   [groovy]     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)

Here are the exact classes
verbatim from the GORM page:
*-------------------------------------------------
class Author {
    @Property Long id
    @Property Long version

    @Property relatesToMany = [ books : Book.class]

    @Property String name
    @Property Set books = new HashSet()
   
    def addBook(book) {
      if(books==null)books = new HashSet()
      book.author = this
      books.add(book)
      return this
    }
}
*-------------------------------------------------
class Book {
    @Property Long id
    @Property Long version

    @Property String title
    @Property String author
}
*-------------------------------------------------
class ApplicationBootStrap {

  @Property Closure init = { servletContext ->
    def a = new Author(name:"Stephen King")
    def b = new Book(title:"The Shining")
    a.addBook(b)
    a.save()  
  }
 
  @Property Closure destroy = {
  }
}
*-------------------------------------------------
class ApplicationDataSource {
   @Property boolean pooled = true
   @Property String dbCreate = "create-drop" // one of 'create', 'create-drop','update'
   @Property String url = "jdbc:hsqldb:mem:testDB"
   @Property String driverClassName = "org.hsqldb.jdbcDriver"
   @Property String username = "sa"
   @Property String password = ""
}


______________________________________________________________________
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

Katun Corporation -- www.katun.com
_____________________________________________________________________
Reply | Threaded
Open this post in threaded view
|

Re: relatesToMany

graemer
I tried the code and it does work. You do sometimes get this error
when reloading bidirectional one-to-many relationships as Hibernate
attempts to bind to the runtime meta model twice. I'm not sure of a
way round this of this writing.

As for your example though your Book class has an author property
which is a String so the addBook method would not work anyway as it
attempts to assign 'this' ie a Book to a string value. Maybe I should
change the example the GORM site to exclude this String version of
author to avoid confusion

Graeme

On 3/21/06, Jonathan Carlson <[hidden email]> wrote:

> I just realized that my earlier "solution" of changing @Property to Map for relatesToMany doesn't actually work because the many field never gets populated.
>
> I'm baffled.  Below I'm using the exact example from the GORM page but "@Property relatesToMany=[ books:Book.class]" throws the Hibernate error below.  This must be happening to others too. Can someone else try this?  It happens to me with both JDK 1.4 and 1.5.
>
>    [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: property mapping has wrong number of columns: Author.relatesToMany type: object
>    [groovy] org.hibernate.MappingException: property mapping has wrong number of columns: Author.relatesToMany type: object
>    [groovy]     at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:396)
>    [groovy]     at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
>    [groovy]     at org.hibernate.cfg.Configuration.validate(Configuration.java:984)
>    [groovy]     at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1169)
>    [groovy]     at org.codehaus.groovy.grails.orm.hibernate.cfg.DefaultGrailsDomainConfiguration.buildSessionFactory(DefaultGrailsDomainConfiguration.java:93)
>    [groovy]     at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:800)
>    [groovy]     at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:726)
>    [groovy]     at org.codehaus.groovy.grails.orm.hibernate.ConfigurableLocalSessionFactoryBean.afterPropertiesSet(ConfigurableLocalSessionFactoryBean.java:92)
>    [groovy]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1059)
>    [groovy]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:363)
>    [groovy]     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)
>
> Here are the exact classes
> verbatim from the GORM page:
> *-------------------------------------------------
> class Author {
>     @Property Long id
>     @Property Long version
>
>     @Property relatesToMany = [ books : Book.class]
>
>     @Property String name
>     @Property Set books = new HashSet()
>
>     def addBook(book) {
>       if(books==null)books = new HashSet()
>       book.author = this
>       books.add(book)
>       return this
>     }
> }
> *-------------------------------------------------
> class Book {
>     @Property Long id
>     @Property Long version
>
>     @Property String title
>     @Property String author
> }
> *-------------------------------------------------
> class ApplicationBootStrap {
>
>   @Property Closure init = { servletContext ->
>     def a = new Author(name:"Stephen King")
>     def b = new Book(title:"The Shining")
>     a.addBook(b)
>     a.save()
>   }
>
>   @Property Closure destroy = {
>   }
> }
> *-------------------------------------------------
> class ApplicationDataSource {
>    @Property boolean pooled = true
>    @Property String dbCreate = "create-drop" // one of 'create', 'create-drop','update'
>    @Property String url = "jdbc:hsqldb:mem:testDB"
>    @Property String driverClassName = "org.hsqldb.jdbcDriver"
>    @Property String username = "sa"
>    @Property String password = ""
> }
>
>
> ______________________________________________________________________
> This email and any files transmitted with it are confidential and
> intended solely for the use of the individual or entity to whom they
> are addressed. If you have received this email in error please notify
> the system manager.
>
> Katun Corporation -- www.katun.com
> _____________________________________________________________________
>
Reply | Threaded
Open this post in threaded view
|

Re: relatesToMany

Jonathan Carlson
In reply to this post by Jonathan Carlson
Graeme wrote:
> I tried the code and it does work. You do sometimes get this error
when reloading bidirectional one-to-many relationships as Hibernate
attempts to bind to the runtime meta model twice. I'm not sure of a
way round this of this writing.

Thanks Graeme.  It would help me to know some things like:
  1) Are you using the latest CVS head like I am?  
  2) Which Java version are you using?  I'ved tried it with 1.4.2 and
1.5.0_04 on Windoze.

I'm rather discouraged because I have never gotten it to accept
@Property relatesToMany.  And Map relatesToMany only silently fails to
manage the relationships.  

Below is more output about what is going on before the error occurs.
It's not reloading data, but setting up Hibernate definitions.  As it is
right now, I'm dead in the water with Grails if I can't do any
one-to-many relationships.  Do you have any other ideas of stuff I might
try?   (BTW, I did try deleting my the grails CVS directory and
downloading everything clean and building again.  No Fix.  :-(  ).

...
   [groovy] [GrailsDomainBinder] Set cascading strategy on property
[relatesToMany] to [null]
   [groovy] [GrailsDomainBinder] Binding persistent property [name]
   [groovy] [GrailsDomainBinder] bound property
[org.codehaus.groovy.grails.commons.DefaultGrailsDomainClassProperty@1ad093c[name=name,type=class
java.lang.String,persistent=true,optional=false,association=false,bidirectional=false,association-type=<null>]]
to column name [NAME]
   [groovy] [GrailsDomainBinder] Set cascading strategy on property
[name] to [null]
   [groovy] Destroying singletons in factory
{org.springframework.beans.factory.support.DefaultListableBeanFactory
defining beans
[customEditors,exceptionHandler,multipartResolver,messageSource,localeChangeInterceptor,localeResolver,dataSource,sessionFactory,transactionManager,AuthorDomainClass,AuthorPersistentClass,AuthorValidator,BookDomainClass,BookPersistentClass,BookValidator,simpleGrailsController,jspViewResolver,handlerMappingTargetSource,handlerMapping,AuthorControllerClass,AuthorControllerTargetSource,AuthorControllerProxy,AuthorController,BookControllerClass,BookControllerTargetSource,BookControllerProxy,BookController,ValidationTagLibClass,ValidationTagLibTargetSource,ValidationTagLibProxy,ValidationTagLib,JavascriptTagLibClass,JavascriptTagLibTargetSource,JavascriptTagLibProxy,JavascriptTagLib,FormTagLibClass,FormTagLibTargetSource,FormTagLibProxy,FormTagLib,ApplicationTagLibClass,ApplicationTagLibTargetSource,ApplicationTagLibProxy,ApplicationTagLib,AuthorScaffoldDomain,AuthorControllerScaffolder,BookScaffoldDomain,BookControllerScaffolder];
parent:
org.springframework.beans.factory.support.DefaultListableBeanFactory
defining beans[grailsApplication,grailsResourceHolder]; root of
BeanFactory hierarchy}
   [groovy] Context initialization failed
   [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: property mapping has wrong
number of columns: Author.relatesToMany type: object
   [groovy] org.hibernate.MappingException: property mapping has wrong
number of columns: Author.relatesToMany type: object
   [groovy]     at
org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:396)
   [groovy]     at
org.hibernate.mapping.RootClass.validate(RootClass.java:192)
   [groovy]     at
org.hibernate.cfg.Configuration.validate(Configuration.java:984)
   [groovy]     at
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1169)
   [groovy]     at
org.codehaus.groovy.grails.orm.hibernate.cfg.DefaultGrailsDomainConfiguration.buildSessionFactory(DefaultGrailsDomainConf
iguration.java:93)



>>> [hidden email] 2006-03-21 11:31:57 AM >>>
I tried the code and it does work. You do sometimes get this error
when reloading bidirectional one-to-many relationships as Hibernate
attempts to bind to the runtime meta model twice. I'm not sure of a
way round this of this writing.

As for your example though your Book class has an author property
which is a String so the addBook method would not work anyway as it
attempts to assign 'this' ie a Book to a string value. Maybe I should
change the example the GORM site to exclude this String version of
author to avoid confusion

Graeme

On 3/21/06, Jonathan Carlson <[hidden email]> wrote:
> I just realized that my earlier "solution" of changing @Property to
Map for relatesToMany doesn't actually work because the many field never
gets populated.
>
> I'm baffled.  Below I'm using the exact example from the GORM page
but "@Property relatesToMany=[ books:Book.class]" throws the Hibernate
error below.  This must be happening to others too. Can someone else try
this?  It happens to me with both JDK 1.4 and 1.5.
>
>    [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: property mapping has wrong
number of columns: Author.relatesToMany type: object
>    [groovy] org.hibernate.MappingException: property mapping has
wrong number of columns: Author.relatesToMany type: object
>    [groovy]     at
org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:396)
>    [groovy]     at
org.hibernate.mapping.RootClass.validate(RootClass.java:192)
>    [groovy]     at
org.hibernate.cfg.Configuration.validate(Configuration.java:984)
>    [groovy]     at
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1169)
>    [groovy]     at
org.codehaus.groovy.grails.orm.hibernate.cfg.DefaultGrailsDomainConfiguration.buildSessionFactory(DefaultGrailsDomainConfiguration.java:93)
>    [groovy]     at
org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:800)
>    [groovy]     at
org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:726)
>    [groovy]     at
org.codehaus.groovy.grails.orm.hibernate.ConfigurableLocalSessionFactoryBean.afterPropertiesSet(ConfigurableLocalSessionFactoryBean.java:92)
>    [groovy]     at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1059)
>    [groovy]     at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:363)
>    [groovy]     at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)

>
> Here are the exact classes
> verbatim from the GORM page:
> *-------------------------------------------------
> class Author {
>     @Property Long id
>     @Property Long version
>
>     @Property relatesToMany = [ books : Book.class]
>
>     @Property String name
>     @Property Set books = new HashSet()
>
>     def addBook(book) {
>       if(books==null)books = new HashSet()
>       book.author = this
>       books.add(book)
>       return this
>     }
> }
> *-------------------------------------------------
> class Book {
>     @Property Long id
>     @Property Long version
>
>     @Property String title
>     @Property String author
> }
> *-------------------------------------------------
> class ApplicationBootStrap {
>
>   @Property Closure init = { servletContext ->
>     def a = new Author(name:"Stephen King")
>     def b = new Book(title:"The Shining")
>     a.addBook(b)
>     a.save()
>   }
>
>   @Property Closure destroy = {
>   }
> }
> *-------------------------------------------------
> class ApplicationDataSource {
>    @Property boolean pooled = true
>    @Property String dbCreate = "create-drop" // one of 'create',
'create-drop','update'
>    @Property String url = "jdbc:hsqldb:mem:testDB"
>    @Property String driverClassName = "org.hsqldb.jdbcDriver"
>    @Property String username = "sa"
>    @Property String password = ""
> }
>______________________________________________________________________

______________________________________________________________________
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

Katun Corporation -- www.katun.com
_____________________________________________________________________
Reply | Threaded
Open this post in threaded view
|

Re: relatesToMany

graemer
1) Yes I am, at least I hope so as I've committed to it several times today :-)
2) JDK 1.4.2, 1.5.0_06 and BEA JRocket 1.5

Which Grails CVS are you using? We did recently migrate to a new repo
and you could be using old code. For example try renaming
'relatesToMany' to 'relationships' and then see if it works. If it
does, you are using old code

Graeme

On 3/22/06, Jonathan Carlson <[hidden email]> wrote:

> Graeme wrote:
> > I tried the code and it does work. You do sometimes get this error
> when reloading bidirectional one-to-many relationships as Hibernate
> attempts to bind to the runtime meta model twice. I'm not sure of a
> way round this of this writing.
>
> Thanks Graeme.  It would help me to know some things like:
>  1) Are you using the latest CVS head like I am?
>  2) Which Java version are you using?  I'ved tried it with 1.4.2 and
> 1.5.0_04 on Windoze.
>
> I'm rather discouraged because I have never gotten it to accept
> @Property relatesToMany.  And Map relatesToMany only silently fails to
> manage the relationships.
>
> Below is more output about what is going on before the error occurs.
> It's not reloading data, but setting up Hibernate definitions.  As it is
> right now, I'm dead in the water with Grails if I can't do any
> one-to-many relationships.  Do you have any other ideas of stuff I might
> try?   (BTW, I did try deleting my the grails CVS directory and
> downloading everything clean and building again.  No Fix.  :-(  ).
>
> ...
>   [groovy] [GrailsDomainBinder] Set cascading strategy on property
> [relatesToMany] to [null]
>   [groovy] [GrailsDomainBinder] Binding persistent property [name]
>   [groovy] [GrailsDomainBinder] bound property
> [org.codehaus.groovy.grails.commons.DefaultGrailsDomainClassProperty@1ad093c[name=name,type=class
> java.lang.String,persistent=true,optional=false,association=false,bidirectional=false,association-type=<null>]]
> to column name [NAME]
>   [groovy] [GrailsDomainBinder] Set cascading strategy on property
> [name] to [null]
>   [groovy] Destroying singletons in factory
> {org.springframework.beans.factory.support.DefaultListableBeanFactory
> defining beans
> [customEditors,exceptionHandler,multipartResolver,messageSource,localeChangeInterceptor,localeResolver,dataSource,sessionFactory,transactionManager,AuthorDomainClass,AuthorPersistentClass,AuthorValidator,BookDomainClass,BookPersistentClass,BookValidator,simpleGrailsController,jspViewResolver,handlerMappingTargetSource,handlerMapping,AuthorControllerClass,AuthorControllerTargetSource,AuthorControllerProxy,AuthorController,BookControllerClass,BookControllerTargetSource,BookControllerProxy,BookController,ValidationTagLibClass,ValidationTagLibTargetSource,ValidationTagLibProxy,ValidationTagLib,JavascriptTagLibClass,JavascriptTagLibTargetSource,JavascriptTagLibProxy,JavascriptTagLib,FormTagLibClass,FormTagLibTargetSource,FormTagLibProxy,FormTagLib,ApplicationTagLibClass,ApplicationTagLibTargetSource,ApplicationTagLibProxy,ApplicationTagLib,AuthorScaffoldDomain,AuthorControllerScaffolder,BookScaffoldDomain,BookControllerScaffolder];
> parent:
> org.springframework.beans.factory.support.DefaultListableBeanFactory
> defining beans[grailsApplication,grailsResourceHolder]; root of
> BeanFactory hierarchy}
>   [groovy] Context initialization failed
>   [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: property mapping has wrong
> number of columns: Author.relatesToMany type: object
>   [groovy] org.hibernate.MappingException: property mapping has wrong
> number of columns: Author.relatesToMany type: object
>   [groovy]     at
> org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:396)
>   [groovy]     at
> org.hibernate.mapping.RootClass.validate(RootClass.java:192)
>   [groovy]     at
> org.hibernate.cfg.Configuration.validate(Configuration.java:984)
>   [groovy]     at
> org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1169)
>   [groovy]     at
> org.codehaus.groovy.grails.orm.hibernate.cfg.DefaultGrailsDomainConfiguration.buildSessionFactory(DefaultGrailsDomainConf
> iguration.java:93)
>
>
>
> >>> [hidden email] 2006-03-21 11:31:57 AM >>>
> I tried the code and it does work. You do sometimes get this error
> when reloading bidirectional one-to-many relationships as Hibernate
> attempts to bind to the runtime meta model twice. I'm not sure of a
> way round this of this writing.
>
> As for your example though your Book class has an author property
> which is a String so the addBook method would not work anyway as it
> attempts to assign 'this' ie a Book to a string value. Maybe I should
> change the example the GORM site to exclude this String version of
> author to avoid confusion
>
> Graeme
>
> On 3/21/06, Jonathan Carlson <[hidden email]> wrote:
> > I just realized that my earlier "solution" of changing @Property to
> Map for relatesToMany doesn't actually work because the many field never
> gets populated.
> >
> > I'm baffled.  Below I'm using the exact example from the GORM page
> but "@Property relatesToMany=[ books:Book.class]" throws the Hibernate
> error below.  This must be happening to others too. Can someone else try
> this?  It happens to me with both JDK 1.4 and 1.5.
> >
> >    [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: property mapping has wrong
> number of columns: Author.relatesToMany type: object
> >    [groovy] org.hibernate.MappingException: property mapping has
> wrong number of columns: Author.relatesToMany type: object
> >    [groovy]     at
> org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:396)
> >    [groovy]     at
> org.hibernate.mapping.RootClass.validate(RootClass.java:192)
> >    [groovy]     at
> org.hibernate.cfg.Configuration.validate(Configuration.java:984)
> >    [groovy]     at
> org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1169)
> >    [groovy]     at
> org.codehaus.groovy.grails.orm.hibernate.cfg.DefaultGrailsDomainConfiguration.buildSessionFactory(DefaultGrailsDomainConfiguration.java:93)
> >    [groovy]     at
> org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:800)
> >    [groovy]     at
> org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:726)
> >    [groovy]     at
> org.codehaus.groovy.grails.orm.hibernate.ConfigurableLocalSessionFactoryBean.afterPropertiesSet(ConfigurableLocalSessionFactoryBean.java:92)
> >    [groovy]     at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1059)
> >    [groovy]     at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:363)
> >    [groovy]     at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)
> >
> > Here are the exact classes
> > verbatim from the GORM page:
> > *-------------------------------------------------
> > class Author {
> >     @Property Long id
> >     @Property Long version
> >
> >     @Property relatesToMany = [ books : Book.class]
> >
> >     @Property String name
> >     @Property Set books = new HashSet()
> >
> >     def addBook(book) {
> >       if(books==null)books = new HashSet()
> >       book.author = this
> >       books.add(book)
> >       return this
> >     }
> > }
> > *-------------------------------------------------
> > class Book {
> >     @Property Long id
> >     @Property Long version
> >
> >     @Property String title
> >     @Property String author
> > }
> > *-------------------------------------------------
> > class ApplicationBootStrap {
> >
> >   @Property Closure init = { servletContext ->
> >     def a = new Author(name:"Stephen King")
> >     def b = new Book(title:"The Shining")
> >     a.addBook(b)
> >     a.save()
> >   }
> >
> >   @Property Closure destroy = {
> >   }
> > }
> > *-------------------------------------------------
> > class ApplicationDataSource {
> >    @Property boolean pooled = true
> >    @Property String dbCreate = "create-drop" // one of 'create',
> 'create-drop','update'
> >    @Property String url = "jdbc:hsqldb:mem:testDB"
> >    @Property String driverClassName = "org.hsqldb.jdbcDriver"
> >    @Property String username = "sa"
> >    @Property String password = ""
> > }
> >______________________________________________________________________
>
> ______________________________________________________________________
> This email and any files transmitted with it are confidential and
> intended solely for the use of the individual or entity to whom they
> are addressed. If you have received this email in error please notify
> the system manager.
>
> Katun Corporation -- www.katun.com
> _____________________________________________________________________
>
Reply | Threaded
Open this post in threaded view
|

Re: relatesToMany

Guillaume Laforge-2
Time to remove the old code from the Groovy repository?

On 3/22/06, Graeme Rocher <[hidden email]> wrote:

> 1) Yes I am, at least I hope so as I've committed to it several times today :-)
> 2) JDK 1.4.2, 1.5.0_06 and BEA JRocket 1.5
>
> Which Grails CVS are you using? We did recently migrate to a new repo
> and you could be using old code. For example try renaming
> 'relatesToMany' to 'relationships' and then see if it works. If it
> does, you are using old code
>
> Graeme
>
> On 3/22/06, Jonathan Carlson <[hidden email]> wrote:
> > Graeme wrote:
> > > I tried the code and it does work. You do sometimes get this error
> > when reloading bidirectional one-to-many relationships as Hibernate
> > attempts to bind to the runtime meta model twice. I'm not sure of a
> > way round this of this writing.
> >
> > Thanks Graeme.  It would help me to know some things like:
> >  1) Are you using the latest CVS head like I am?
> >  2) Which Java version are you using?  I'ved tried it with 1.4.2 and
> > 1.5.0_04 on Windoze.
> >
> > I'm rather discouraged because I have never gotten it to accept
> > @Property relatesToMany.  And Map relatesToMany only silently fails to
> > manage the relationships.
> >
> > Below is more output about what is going on before the error occurs.
> > It's not reloading data, but setting up Hibernate definitions.  As it is
> > right now, I'm dead in the water with Grails if I can't do any
> > one-to-many relationships.  Do you have any other ideas of stuff I might
> > try?   (BTW, I did try deleting my the grails CVS directory and
> > downloading everything clean and building again.  No Fix.  :-(  ).
> >
> > ...
> >   [groovy] [GrailsDomainBinder] Set cascading strategy on property
> > [relatesToMany] to [null]
> >   [groovy] [GrailsDomainBinder] Binding persistent property [name]
> >   [groovy] [GrailsDomainBinder] bound property
> > [org.codehaus.groovy.grails.commons.DefaultGrailsDomainClassProperty@1ad093c[name=name,type=class
> > java.lang.String,persistent=true,optional=false,association=false,bidirectional=false,association-type=<null>]]
> > to column name [NAME]
> >   [groovy] [GrailsDomainBinder] Set cascading strategy on property
> > [name] to [null]
> >   [groovy] Destroying singletons in factory
> > {org.springframework.beans.factory.support.DefaultListableBeanFactory
> > defining beans
> > [customEditors,exceptionHandler,multipartResolver,messageSource,localeChangeInterceptor,localeResolver,dataSource,sessionFactory,transactionManager,AuthorDomainClass,AuthorPersistentClass,AuthorValidator,BookDomainClass,BookPersistentClass,BookValidator,simpleGrailsController,jspViewResolver,handlerMappingTargetSource,handlerMapping,AuthorControllerClass,AuthorControllerTargetSource,AuthorControllerProxy,AuthorController,BookControllerClass,BookControllerTargetSource,BookControllerProxy,BookController,ValidationTagLibClass,ValidationTagLibTargetSource,ValidationTagLibProxy,ValidationTagLib,JavascriptTagLibClass,JavascriptTagLibTargetSource,JavascriptTagLibProxy,JavascriptTagLib,FormTagLibClass,FormTagLibTargetSource,FormTagLibProxy,FormTagLib,ApplicationTagLibClass,ApplicationTagLibTargetSource,ApplicationTagLibProxy,ApplicationTagLib,AuthorScaffoldDomain,AuthorControllerScaffolder,BookScaffoldDomain,BookControllerScaffolder];
> > parent:
> > org.springframework.beans.factory.support.DefaultListableBeanFactory
> > defining beans[grailsApplication,grailsResourceHolder]; root of
> > BeanFactory hierarchy}
> >   [groovy] Context initialization failed
> >   [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: property mapping has wrong
> > number of columns: Author.relatesToMany type: object
> >   [groovy] org.hibernate.MappingException: property mapping has wrong
> > number of columns: Author.relatesToMany type: object
> >   [groovy]     at
> > org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:396)
> >   [groovy]     at
> > org.hibernate.mapping.RootClass.validate(RootClass.java:192)
> >   [groovy]     at
> > org.hibernate.cfg.Configuration.validate(Configuration.java:984)
> >   [groovy]     at
> > org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1169)
> >   [groovy]     at
> > org.codehaus.groovy.grails.orm.hibernate.cfg.DefaultGrailsDomainConfiguration.buildSessionFactory(DefaultGrailsDomainConf
> > iguration.java:93)
> >
> >
> >
> > >>> [hidden email] 2006-03-21 11:31:57 AM >>>
> > I tried the code and it does work. You do sometimes get this error
> > when reloading bidirectional one-to-many relationships as Hibernate
> > attempts to bind to the runtime meta model twice. I'm not sure of a
> > way round this of this writing.
> >
> > As for your example though your Book class has an author property
> > which is a String so the addBook method would not work anyway as it
> > attempts to assign 'this' ie a Book to a string value. Maybe I should
> > change the example the GORM site to exclude this String version of
> > author to avoid confusion
> >
> > Graeme
> >
> > On 3/21/06, Jonathan Carlson <[hidden email]> wrote:
> > > I just realized that my earlier "solution" of changing @Property to
> > Map for relatesToMany doesn't actually work because the many field never
> > gets populated.
> > >
> > > I'm baffled.  Below I'm using the exact example from the GORM page
> > but "@Property relatesToMany=[ books:Book.class]" throws the Hibernate
> > error below.  This must be happening to others too. Can someone else try
> > this?  It happens to me with both JDK 1.4 and 1.5.
> > >
> > >    [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: property mapping has wrong
> > number of columns: Author.relatesToMany type: object
> > >    [groovy] org.hibernate.MappingException: property mapping has
> > wrong number of columns: Author.relatesToMany type: object
> > >    [groovy]     at
> > org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:396)
> > >    [groovy]     at
> > org.hibernate.mapping.RootClass.validate(RootClass.java:192)
> > >    [groovy]     at
> > org.hibernate.cfg.Configuration.validate(Configuration.java:984)
> > >    [groovy]     at
> > org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1169)
> > >    [groovy]     at
> > org.codehaus.groovy.grails.orm.hibernate.cfg.DefaultGrailsDomainConfiguration.buildSessionFactory(DefaultGrailsDomainConfiguration.java:93)
> > >    [groovy]     at
> > org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:800)
> > >    [groovy]     at
> > org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:726)
> > >    [groovy]     at
> > org.codehaus.groovy.grails.orm.hibernate.ConfigurableLocalSessionFactoryBean.afterPropertiesSet(ConfigurableLocalSessionFactoryBean.java:92)
> > >    [groovy]     at
> > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1059)
> > >    [groovy]     at
> > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:363)
> > >    [groovy]     at
> > org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)
> > >
> > > Here are the exact classes
> > > verbatim from the GORM page:
> > > *-------------------------------------------------
> > > class Author {
> > >     @Property Long id
> > >     @Property Long version
> > >
> > >     @Property relatesToMany = [ books : Book.class]
> > >
> > >     @Property String name
> > >     @Property Set books = new HashSet()
> > >
> > >     def addBook(book) {
> > >       if(books==null)books = new HashSet()
> > >       book.author = this
> > >       books.add(book)
> > >       return this
> > >     }
> > > }
> > > *-------------------------------------------------
> > > class Book {
> > >     @Property Long id
> > >     @Property Long version
> > >
> > >     @Property String title
> > >     @Property String author
> > > }
> > > *-------------------------------------------------
> > > class ApplicationBootStrap {
> > >
> > >   @Property Closure init = { servletContext ->
> > >     def a = new Author(name:"Stephen King")
> > >     def b = new Book(title:"The Shining")
> > >     a.addBook(b)
> > >     a.save()
> > >   }
> > >
> > >   @Property Closure destroy = {
> > >   }
> > > }
> > > *-------------------------------------------------
> > > class ApplicationDataSource {
> > >    @Property boolean pooled = true
> > >    @Property String dbCreate = "create-drop" // one of 'create',
> > 'create-drop','update'
> > >    @Property String url = "jdbc:hsqldb:mem:testDB"
> > >    @Property String driverClassName = "org.hsqldb.jdbcDriver"
> > >    @Property String username = "sa"
> > >    @Property String password = ""
> > > }
> > >______________________________________________________________________
> >
> > ______________________________________________________________________
> > This email and any files transmitted with it are confidential and
> > intended solely for the use of the individual or entity to whom they
> > are addressed. If you have received this email in error please notify
> > the system manager.
> >
> > Katun Corporation -- www.katun.com
> > _____________________________________________________________________
> >
>


--
Guillaume Laforge
Groovy Project Manager
http://glaforge.free.fr/blog/groovy
Reply | Threaded
Open this post in threaded view
|

Re: relatesToMany

Jonathan Carlson
In reply to this post by Jonathan Carlson
Doh!  I'm using the one in groovy/modules/grails.  

Thank you, thank you, thank you!  I was about to despair.  (Well, not
quite that easily :-)



>>> [hidden email] 2006-03-22 3:00:10 PM >>>
1) Yes I am, at least I hope so as I've committed to it several times
today :-)
2) JDK 1.4.2, 1.5.0_06 and BEA JRocket 1.5

Which Grails CVS are you using? We did recently migrate to a new repo
and you could be using old code. For example try renaming
'relatesToMany' to 'relationships' and then see if it works. If it
does, you are using old code

Graeme

On 3/22/06, Jonathan Carlson <[hidden email]> wrote:

> Graeme wrote:
> > I tried the code and it does work. You do sometimes get this error
> when reloading bidirectional one-to-many relationships as Hibernate
> attempts to bind to the runtime meta model twice. I'm not sure of a
> way round this of this writing.
>
> Thanks Graeme.  It would help me to know some things like:
>  1) Are you using the latest CVS head like I am?
>  2) Which Java version are you using?  I'ved tried it with 1.4.2 and
> 1.5.0_04 on Windoze.
>
> I'm rather discouraged because I have never gotten it to accept
> @Property relatesToMany.  And Map relatesToMany only silently fails
to
> manage the relationships.
>
> Below is more output about what is going on before the error occurs.
> It's not reloading data, but setting up Hibernate definitions.  As it
is
> right now, I'm dead in the water with Grails if I can't do any
> one-to-many relationships.  Do you have any other ideas of stuff I
might
> try?   (BTW, I did try deleting my the grails CVS directory and
> downloading everything clean and building again.  No Fix.  :-(  ).
>
> ...
>   [groovy] [GrailsDomainBinder] Set cascading strategy on property
> [relatesToMany] to [null]
>   [groovy] [GrailsDomainBinder] Binding persistent property [name]
>   [groovy] [GrailsDomainBinder] bound property
>
[org.codehaus.groovy.grails.commons.DefaultGrailsDomainClassProperty@1ad093c[name=name,type=class
>
java.lang.String,persistent=true,optional=false,association=false,bidirectional=false,association-type=<null>]]
> to column name [NAME]
>   [groovy] [GrailsDomainBinder] Set cascading strategy on property
> [name] to [null]
>   [groovy] Destroying singletons in factory
>
{org.springframework.beans.factory.support.DefaultListableBeanFactory
> defining beans
>
[customEditors,exceptionHandler,multipartResolver,messageSource,localeChangeInterceptor,localeResolver,dataSource,sessionFactory,transactionManager,AuthorDomainClass,AuthorPersistentClass,AuthorValidator,BookDomainClass,BookPersistentClass,BookValidator,simpleGrailsController,jspViewResolver,handlerMappingTargetSource,handlerMapping,AuthorControllerClass,AuthorControllerTargetSource,AuthorControllerProxy,AuthorController,BookControllerClass,BookControllerTargetSource,BookControllerProxy,BookController,ValidationTagLibClass,ValidationTagLibTargetSource,ValidationTagLibProxy,ValidationTagLib,JavascriptTagLibClass,JavascriptTagLibTargetSource,JavascriptTagLibProxy,JavascriptTagLib,FormTagLibClass,FormTagLibTargetSource,FormTagLibProxy,FormTagLib,ApplicationTagLibClass,ApplicationTagLibTargetSource,ApplicationTagLibProxy,ApplicationTagLib,AuthorScaffoldDomain,AuthorControllerScaffolder,BookScaffoldDomain,BookControllerScaffolder];
> parent:
> org.springframework.beans.factory.support.DefaultListableBeanFactory
> defining beans[grailsApplication,grailsResourceHolder]; root of
> BeanFactory hierarchy}
>   [groovy] Context initialization failed
>   [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: property mapping has
wrong
> number of columns: Author.relatesToMany type: object
>   [groovy] org.hibernate.MappingException: property mapping has
wrong
> number of columns: Author.relatesToMany type: object
>   [groovy]     at
>
org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:396)
>   [groovy]     at
> org.hibernate.mapping.RootClass.validate(RootClass.java:192)
>   [groovy]     at
> org.hibernate.cfg.Configuration.validate(Configuration.java:984)
>   [groovy]     at
>
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1169)
>   [groovy]     at
>
org.codehaus.groovy.grails.orm.hibernate.cfg.DefaultGrailsDomainConfiguration.buildSessionFactory(DefaultGrailsDomainConf

> iguration.java:93)
>
>
>
> >>> [hidden email] 2006-03-21 11:31:57 AM >>>
> I tried the code and it does work. You do sometimes get this error
> when reloading bidirectional one-to-many relationships as Hibernate
> attempts to bind to the runtime meta model twice. I'm not sure of a
> way round this of this writing.
>
> As for your example though your Book class has an author property
> which is a String so the addBook method would not work anyway as it
> attempts to assign 'this' ie a Book to a string value. Maybe I
should
> change the example the GORM site to exclude this String version of
> author to avoid confusion
>
> Graeme
>
> On 3/21/06, Jonathan Carlson <[hidden email]> wrote:
> > I just realized that my earlier "solution" of changing @Property
to
> Map for relatesToMany doesn't actually work because the many field
never
> gets populated.
> >
> > I'm baffled.  Below I'm using the exact example from the GORM page
> but "@Property relatesToMany=[ books:Book.class]" throws the
Hibernate
> error below.  This must be happening to others too. Can someone else
try
> this?  It happens to me with both JDK 1.4 and 1.5.
> >
> >    [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: property mapping has
wrong
> number of columns: Author.relatesToMany type: object
> >    [groovy] org.hibernate.MappingException: property mapping has
> wrong number of columns: Author.relatesToMany type: object
> >    [groovy]     at
>
org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:396)
> >    [groovy]     at
> org.hibernate.mapping.RootClass.validate(RootClass.java:192)
> >    [groovy]     at
> org.hibernate.cfg.Configuration.validate(Configuration.java:984)
> >    [groovy]     at
>
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1169)
> >    [groovy]     at
>
org.codehaus.groovy.grails.orm.hibernate.cfg.DefaultGrailsDomainConfiguration.buildSessionFactory(DefaultGrailsDomainConfiguration.java:93)
> >    [groovy]     at
>
org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:800)
> >    [groovy]     at
>
org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:726)
> >    [groovy]     at
>
org.codehaus.groovy.grails.orm.hibernate.ConfigurableLocalSessionFactoryBean.afterPropertiesSet(ConfigurableLocalSessionFactoryBean.java:92)
> >    [groovy]     at
>
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1059)
> >    [groovy]     at
>
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:363)
> >    [groovy]     at
>
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)

> >
> > Here are the exact classes
> > verbatim from the GORM page:
> > *-------------------------------------------------
> > class Author {
> >     @Property Long id
> >     @Property Long version
> >
> >     @Property relatesToMany = [ books : Book.class]
> >
> >     @Property String name
> >     @Property Set books = new HashSet()
> >
> >     def addBook(book) {
> >       if(books==null)books = new HashSet()
> >       book.author = this
> >       books.add(book)
> >       return this
> >     }
> > }
> > *-------------------------------------------------
> > class Book {
> >     @Property Long id
> >     @Property Long version
> >
> >     @Property String title
> >     @Property String author
> > }
> > *-------------------------------------------------
> > class ApplicationBootStrap {
> >
> >   @Property Closure init = { servletContext ->
> >     def a = new Author(name:"Stephen King")
> >     def b = new Book(title:"The Shining")
> >     a.addBook(b)
> >     a.save()
> >   }
> >
> >   @Property Closure destroy = {
> >   }
> > }
> > *-------------------------------------------------
> > class ApplicationDataSource {
> >    @Property boolean pooled = true
> >    @Property String dbCreate = "create-drop" // one of 'create',
> 'create-drop','update'
> >    @Property String url = "jdbc:hsqldb:mem:testDB"
> >    @Property String driverClassName = "org.hsqldb.jdbcDriver"
> >    @Property String username = "sa"
> >    @Property String password = ""
> > }
>
>______________________________________________________________________
>
>
______________________________________________________________________
> This email and any files transmitted with it are confidential and
> intended solely for the use of the individual or entity to whom they
> are addressed. If you have received this email in error please
notify
> the system manager.
>
> Katun Corporation -- www.katun.com
>
_____________________________________________________________________
>

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

______________________________________________________________________
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

Katun Corporation -- www.katun.com
_____________________________________________________________________