Micor
Micor

Reputation: 1542

Setting metaClass property on domain object

Any reason not to use metaClass on domain objects? as in

domainObjectInstance.metaClass.dynamicTransientGreeting = "Hello"

Will this mess with hibernate at all?

Upvotes: 0

Views: 320

Answers (1)

Burt Beckwith
Burt Beckwith

Reputation: 75671

It won't mess with Hibernate at all since it won't be seen by Hibernate. GORM only maps "real" properties to Hibernate properties.

That's why the id and version columns and the collections that are generated from hasMany declarations (e.g. the users collection generated by static hasMany = [users: User] are added to the actual bytecode using an AST. If they were added just to the MetaClass they wouldn't be seen and wouldn't be persistent.

Upvotes: 2

Related Questions