This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

disassociate 2 domain objects

 
Maharaj thak
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When posting code, please remember to UseCodeTags. Our system makes non-formatted code really difficult to read.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic