在我的应用程序中,我有一组1000个左右的“HouseProto”域对象,它们在我的“HouseInstance”对象中有一堆静态属性。
在规模上,可能会有很多HouseInstance对象,每个对象都在HouseProtos上建模。以下是我尝试对HouseInstance域对象进行建模的方法。
class HouseInstance {
@Delegate
HouseProto houseProto
User agent
static belongsTo=[world: World]
static constraints = {
agent nullable:true
}
}
HouseProto有很多字段,如“squareFeet”和“bedroomCount”等。 我使用@Delegate注释,因为我希望能够做类似
的事情houseInstance.streetAddress
而不是
houseInstance.houseProto.streetAddress
但这在编译时失败了。埋在控制台输出结尾处的是对HouseProto(一个hasMany Set)的“features”字段的引用,该字段暗示可能与它有关。删除委托注释,但一切正常。 (Feature是属于HouseProto的域类。)
我的问题是@Delegate注释是否与Domain类不兼容,因为它因某些原因干扰了GORM?如果它可以编译,它似乎会做我想要的。
HouseProto或多或少看起来像这样:
class HouseProto {
def houseService
String streetAddress
Owner owner
Integer sqft
Double acreage
Integer bedroom
...
Double kitchenQuality =0
Double loanBalance =0
Neighborhood neighborhood
String toString() {
"$streetAddress"
}
static hasMany = [features: Feature]
static constraints = {
streetAddress nullable: false, unique: true;
owner nullable: true
sqft nullable: false
neighborhood nullable: false
}
}
运行时控制台输出以此开头:
ERROR org.springframework.boot.context.embedded.tomcat.TomcatStarter - Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'grailsCacheFilter': Cannot create inner bean '(inner bean)#5ec1152d' of type [grails.plugin.cache.web.filter.simple.MemoryPageFragmentCachingFilter] while setting bean property 'filter'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name '(inner bean)#5ec1152d': Unsatisfied dependency expressed through method 'setUrlMappingsHandlerMapping' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'urlMappingsHandlerMapping': Unsatisfied dependency expressed through method 'setWebRequestInterceptors' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'openSessionInViewInterceptor': Cannot resolve reference to bean 'hibernateDatastore' while setting bean property 'hibernateDatastore'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateDatastore': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.grails.orm.hibernate.HibernateDatastore]: Constructor threw exception; nested exception is org.hibernate.MappingException: collection element mapping has wrong number of columns: com.grapevine.negotiator2.HouseInstance.features type: object
与目标虚拟机断开连接,地址:'127.0.0.1:57570',传输:'socket'
ERROR org.springframework.boot.SpringApplication - Application startup failed
答案 0 :(得分:1)
据我所知,域名不支持@Delegate
,您可以使用HouseInstance
和HouseProto
实施