可以创建未映射到数据库表的域类吗? [英] Possible to create a domain class that is NOT mapped to a database table?
问题描述
我正在使用Grails 1.2.1.我正在将Java应用程序转换为Grails应用程序,并且我有一个Java对象,以为可以为其创建grails域.但是,该对象不依赖于基础数据库表.启动我的应用程序时,出现错误
I'm using Grails 1.2.1. I'm converting a Java app to a Grails app and I had a Java object that I thought I'd create a grails domain for. However, the object does not rely on an underlying database table. When I startup my app, I'm getting the error,
错误context.ContextLoader-上下文初始化失败 org.springframework.beans.factory.BeanCreationException:创建名称为'messageSource'的bean时出错:初始化bean失败;嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建名称为'transactionManager'的bean时出错:设置bean属性'sessionFactory'时无法解析对bean'sessionFactory'的引用;嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建名称为'sessionFactory'的bean时出错:调用init方法失败;嵌套的异常是org.hibernate.MappingException:无法确定类型:java.io.InputStream,在表:http_cache_response,对于列:[org.hibernate.mapping.Column(body)]"
"ERROR context.ContextLoader - Context initialization failed 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 org.hibernate.MappingException: Could not determine type for: java.io.InputStream, at table: http_cache_response, for columns: [org.hibernate.mapping.Column(body)]"
我滥用域名了吗?这个对象应该只是src/groovy中的常规类吗?谢谢,-戴夫
Am I misusing the domain? Should this object just be a regular class in src/groovy? Thanks, - Dave
推荐答案
是的,域对象是特定于数据库的对象.在DDD意义上不属于域.
Yes, domain objects are specifically database-mapped objects. Not domain in the DDD sense.
取决于类是否为单例,它应该是服务还是src/groovy中的类.
Depending on if the class is a singleton or not it should either be a service or a class in src/groovy.
这篇关于可以创建未映射到数据库表的域类吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!