我在Grails 3.0.10中创建了一个新的web-api配置文件项目,并尝试设置一个像这样的简单域类层次结构......
//这是在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)
如果我从类获取者中删除“扩展组织”,一切正常。
对此有何建议?
答案 0 :(得分:0)
它认为您的问题是DomainObject
不是域类。你可以使它成为一个域类,但我怀疑一个特性更适合你的情况。
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
}
}