IntelliJ Java IDE
The moose likes Groovy and the fly likes disassociate 2 domain objects Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Other Languages » Groovy
Reply 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: 21
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
Sheriff

Joined: Jul 11, 2001
Posts: 15040

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.


My Blog | DZone Articles
Gregg Bolinger
Sheriff

Joined: Jul 11, 2001
Posts: 15040

When posting code, please remember to UseCodeTags. Our system makes non-formatted code really difficult to read.
 
 
subject: disassociate 2 domain objects
 
Threads others viewed
Explation of Object Identity
EJB 3.0 Entity Bean
newbee cant find string
java code problem
create multiple Checkboxes with data base values in jsp
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture