Delete object of my domain in grails e groovy

10 views
Skip to first unread message

Michele Medas

unread,
Jul 23, 2017, 10:29:38 AM7/23/17
to Grails Dev Discuss

Using grails I build this domains:

class Book {
    String title
}

class Author {
    String name

        static hasMany = [books: Book]
}


def book1 = new Book(title: "The Shining")

def author1 = new Author (name: "Stephen King")
author1.addToBooks(book1)

If try to delete Author1

author.books.clear()
Author1.delete flush:true

Get this error:

Message null Caused by Referential integrity constraint violation: "FKQG8TLCGMC6WKG6ILECFOXSLVS: PUBLIC.PROJECT_BOOK FOREIGN KEY(BOOK_AUTHOR_ID) REFERENCES PUBLIC.PROJECT_AUTHOR(ID) (1)"; SQL statement: delete from project_column where id=? and version=? [23503-195]

I would like to delete an author without deleting the books.

Reply all
Reply to author
Forward
0 new messages