Grails 3.0.10 GORM继承
Grails 3.0.10 GORM inheritance
我在 Grails 3.0.10 中创建了一个新的 web-api 配置文件项目,并尝试建立一个像这样的简单域 class 层次结构...
//这个在testapi/src/main/groovy
package test.api.common
class DomainObject {
Date dateCreated
Date lastUpdated
}
这是在testate/grails-app/domain
package test.api
import test.common.DomainObject
class Organization extends DomainObject {
String col1
String col2
static constraints = {
col1 maxSize:35
col2 maxSize:6
}
static mapping = {
tablePerHierarchy false
}
}
class Org1 extends Organization {
String col3
}
当我尝试 运行 时出现以下异常
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.grails.datastore.gorm.config.GrailsDomainClassMappingContext]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:122)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:267)
... 66 more
Caused by: java.lang.NullPointerException
at org.grails.datastore.gorm.config.GrailsDomainClassPersistentEntity.getRootEntity(GrailsDomainClassPersistentEntity.java:203)
at org.grails.datastore.mapping.model.AbstractMappingContext.initializePersistentEntity(AbstractMappingContext.java:259)
at org.grails.datastore.mapping.model.AbstractMappingContext.addPersistentEntities(AbstractMappingContext.java:183)
at org.grails.datastore.gorm.config.GrailsDomainClassMappingContext.<init>(GrailsDomainClassMappingContext.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrConstructorNewInstance(ReflectiveInterceptor.java:1075)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
如果我从 class Acquirer 中删除 "extends Organization",一切正常。
对此有何建议?
它认为您的问题是 DomainObject
不是域 class。您 可以 将其设为域 class,但我怀疑特征更适合您的情况。
package test.api.common
trait DomainObject {
Date dateCreated
Date lastUpdated
}
package test.api
import test.common.DomainObject
class Organization implements DomainObject {
String col1
String col2
static constraints = {
col1 maxSize:35
col2 maxSize:6
}
static mapping = {
tablePerHierarchy false
}
}
我在 Grails 3.0.10 中创建了一个新的 web-api 配置文件项目,并尝试建立一个像这样的简单域 class 层次结构...
//这个在testapi/src/main/groovy
package test.api.common
class DomainObject {
Date dateCreated
Date lastUpdated
}
这是在testate/grails-app/domain
package test.api
import test.common.DomainObject
class Organization extends DomainObject {
String col1
String col2
static constraints = {
col1 maxSize:35
col2 maxSize:6
}
static mapping = {
tablePerHierarchy false
}
}
class Org1 extends Organization {
String col3
}
当我尝试 运行 时出现以下异常
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.grails.datastore.gorm.config.GrailsDomainClassMappingContext]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:122)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:267)
... 66 more
Caused by: java.lang.NullPointerException
at org.grails.datastore.gorm.config.GrailsDomainClassPersistentEntity.getRootEntity(GrailsDomainClassPersistentEntity.java:203)
at org.grails.datastore.mapping.model.AbstractMappingContext.initializePersistentEntity(AbstractMappingContext.java:259)
at org.grails.datastore.mapping.model.AbstractMappingContext.addPersistentEntities(AbstractMappingContext.java:183)
at org.grails.datastore.gorm.config.GrailsDomainClassMappingContext.<init>(GrailsDomainClassMappingContext.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrConstructorNewInstance(ReflectiveInterceptor.java:1075)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
如果我从 class Acquirer 中删除 "extends Organization",一切正常。
对此有何建议?
它认为您的问题是 DomainObject
不是域 class。您 可以 将其设为域 class,但我怀疑特征更适合您的情况。
package test.api.common
trait DomainObject {
Date dateCreated
Date lastUpdated
}
package test.api
import test.common.DomainObject
class Organization implements DomainObject {
String col1
String col2
static constraints = {
col1 maxSize:35
col2 maxSize:6
}
static mapping = {
tablePerHierarchy false
}
}