1
votes

It's obviously best to put transactional code in Grails services for a lot of different reasons. However, are Domain classes transactional like services are?

It seems to make intuitive sense to put my data-binding for domain specific fields in the domain class and even use some Groovy conventions to make Grails binding work more seamlessly (such as replacing a setSomeField(type A) setSomeField(type B) ... ). I've also been experimenting with handling the domain model relationships manually as suggested by Burt Beckwith for performance and to make the code more flexible. This requires to update and save other domain class instances on a setSomeField(...) call.

That's the background of what I'm doing, but the original question is really: Do Domain classes have the same transactional behavior as Grails services? If not, should I be wrapping the transactions in withTransaction{} or using @Transactional or just using service ?

1

1 Answers

3
votes

No, domain classes' methods are NOT transactional by default. You can apply @Transactional to them or run them in higher-level transactional contexts, like service's.