Last active
August 29, 2015 14:18
-
-
Save frozenspider/b84eba656aea7a077c9b to your computer and use it in GitHub Desktop.
GORM/Hibernate associations test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import test.* | |
Parent.withNewSession { | |
Parent.withNewTransaction { | |
def parent = new Parent() | |
.addToChildren(new Child(name: "a")) | |
.addToChildren(new Child(name: "b")) | |
.addToChildren(new Child(name: "c")) | |
.save(failOnError: true) | |
} | |
} | |
println("=== Status ===") | |
Parent.withNewSession { | |
Parent.withNewTransaction { | |
println(Parent.list()) | |
println(Child.list()) | |
} | |
} | |
println("=== Test deletion before ===") | |
Parent.withNewSession { | |
Parent.withNewTransaction { | |
Child.findByName("b").delete() | |
def parent = Parent.list()[0] | |
println(parent) | |
parent.addToChildren(new Child(name: "d")) | |
parent.save(failOnError: true) | |
println(parent) | |
} | |
} | |
Parent.withNewSession { | |
Parent.withNewTransaction { | |
println(Parent.list()[0]) | |
} | |
} |
Author
frozenspider
commented
Apr 3, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment