开发者

Possible to create a domain class that is NOT mapped to a database table?

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,

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.BeanCreationExcep开发者_如何转开发tion: 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)]

Am I misusing the domain? Should this object just be a regular class in src/groovy? Thanks, - Dave


Yes, domain objects are specifically database-mapped objects. Not domain in the DDD sense.

Depending on if the class is a singleton or not it should either be a service or a class in src/groovy.


It's possible to create a class that does not have an underlying domain object. There are 2 cases:

  1. You want an object to use in Controller, you may create a Command Object.

  2. If you want to create a pure java or groovy class, you can create it in src/java or src/groovy.


You might want to check out mapWith property of domain classes:

static mapWith = "none" should do the trick


I would say if your not going to use the class as a grails style domain object, it's better to put it in src/java and use them like any other class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜