I have a similar problem. I want to save a composite structure to the db, but i keep getting nullpointer exceptions on startup.
My model looks like this:
abstract class Structure {
//Some properties
static constraints = {
}
}
class StructureFolder extends Structure {
//Some properties
static hasMany = [structures : Structure]
static constraints = {
}
}
is something like that possible with GORM? i found no answer and i keep getting this stacktrace:
Error executing script RunApp: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
gant.TargetExecutionException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:331)
at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
at gant.Gant.withBuildListeners(Gant.groovy:344)
at gant.Gant.this$2$withBuildListeners(Gant.groovy)
at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
at gant.Gant.dispatch(Gant.groovy:334)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.processTargets(Gant.groovy:495)
at gant.Gant.processTargets(Gant.groovy:480)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
at java.security.AccessController.doPrivileged(Native Method)
at _GrailsGas3_groovy.initGrailsApp(_GrailsGas3_groovy:215)
at _GrailsGas3_groovy$_run_closure1.doCall(_GrailsGas3_groovy:61)
at _Events$_run_closure2.doCall(_Events.groovy:31)
at _GrailsEvents_groovy$_run_closure5.doCall(_GrailsEvents_groovy:59)
at _GrailsEvents_groovy$_run_closure5.call(_GrailsEvents_groovy)
at _GrailsPackage_groovy$_run_closure2.doCall(_GrailsPackage_groovy:130)
at RunApp$_run_closure1.doCall(RunApp.groovy:28)
at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
... 10 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
at java.security.AccessController.doPrivileged(Native Method)
... 19 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
at java.security.AccessController.doPrivileged(Native Method)
... 20 more
Caused by: java.lang.NullPointerException
... 21 more
ANY idea? Thanks in advance :)
Racker Vijay wrote:
Hello
I have the following domain model.
NewsArticle has many comments.
Event has many comments.
I would like to keep one table for the comments, and a table for NewsArticle and one for Event
To that end, this is what I did in Grails 1.1.1
abstract class CommentableObject {
SortedSet comments
static hasMany = [comments:Comment]
static mapping = {
tablePerHierarchy true
}
}
class NewsArticle extends CommentableObject {
String subject
}
class Event extends CommentableObject {
String title
}
class Comment implements Comparable {
Date date
String body
static belongsTo = [commentableObject:CommentableObject]
}
I keep getting this error on startup
org.hibernate.MappingException: An association from the table comment refers to an unmapped class: CommentableObject
However, if I make the superclass concrete, the error goes away.
what is the right way to map this type of associations