wood burning stoves 2.0*
The moose likes Groovy and the fly likes disassociate 2 domain objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Groovy
Bookmark "disassociate 2 domain objects" Watch "disassociate 2 domain objects" New topic
Author

disassociate 2 domain objects

Maharaj thak
Greenhorn

Joined: Jul 29, 2010
Posts: 27
Hi All
I have 2 domain classes

class Book{
String name

Author author
}

class Author{
String name


}


Now if I do

Author bookAuthor=new Author("BOOk Author").save()
Book book1=new Book(name:"first book",author:bookAuthor).save()
Book book2=new Book(name:"second book",author:bookAuthor).save()
Book book3=new Book(name:"third book",author:bookAuthor).save()

Can I do something like this

book3.author=null

so that I disassociate the book fro its author without deleting it from the database


Regards
Maharaj Thak
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Yes, but only if you define author as nullable in the book constraints. And vice versa for Author. You'll want to make book nullable.


GenRocket - Experts at Building Test Data
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

When posting code, please remember to UseCodeTags. Our system makes non-formatted code really difficult to read.
 
 
subject: disassociate 2 domain objects