1 package org
.codehaus
.groovy
.grails
.orm
.hibernate
;
4 class WithTransactionMethodTests
extends AbstractGrailsHibernateTests
{
6 void testWithTransactionMethod() {
8 def domainClass
= ga
.getDomainClass("Author1")
9 authors
<< domainClass
.newInstance()
10 authors
<< domainClass
.newInstance()
11 authors
<< domainClass
.newInstance()
15 authors
[0].name
= "Stephen King"
16 authors
[1].name
= "John Grisham"
17 authors
[2].name
= "James Patterson"
20 domainClass
.clazz
.withTransaction
{ status
->
25 def results
= domainClass
.clazz
.list()
26 assertEquals
2, results
.size()
28 domainClass
.clazz
.withTransaction
{ status
->
30 status
.setRollbackOnly()
33 results
= domainClass
.clazz
.list()
34 assertEquals
2, results
.size()
44 static belongsTo = Author1
47 boolean equals(obj) { title == obj?.title }
48 int hashCode() { title ? title.hashCode() : super.hashCode() }
49 String toString() { title }
56 static hasMany = [books:Book1]
57 boolean equals(obj) { name == obj?.name }
58 int hashCode() { name ? name.hashCode() : super.hashCode() }
59 String toString() { name }