user3740462
user3740462

Reputation: 1

Grails Throwing Non Unique object exception

How do i call domain.save() multiple times in my application? When I save the domain midway through the application and then save it again when submission of the application it throws a non unique object exception. I've also tried calling .merge() before I submit the application but its throwing an org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect).

Thanks in advance

Upvotes: 0

Views: 673

Answers (1)

schneidermatic
schneidermatic

Reputation: 43

call save flush:true on your domain object and clear the session (see the example below). For more details take a look here: grails.org/doc/latest/guide/GORM.html 7.3 Persistence Basics

Book.withSession { session ->
   Book book = new Book()
   book.title = 'The Definitive Guide To Grails'
   book.save flush:true
   session.clear()
}

Upvotes: 1

Related Questions