Issue Details (XML | Word | Printable)

Key: GRAILS-4426
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Blocker Blocker
Assignee: Graeme Rocher
Reporter: Burt Beckwith
Votes: 1
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
Grails

saving an invalid modified instance in a transactional service fails

Created: 11/Apr/09 11:47 AM   Updated: 27/Jul/09 05:12 AM   Resolved: 22/Apr/09 07:54 AM
Return to search
Component/s: Persistence
Affects Version/s: 1.0.4, 1.1
Fix Version/s: 1.1.1

Time Tracking:
Not Specified

File Attachments: 1. GZip Archive bug.tar.gz (126 kB)



 Description  « Hide

If you retrieve a persistent domain instance and set one or more invalid properties in a controller and attempt to save the instance in a transactional service method, validation isn't performed and the instance is flushed. If one of the validation problems involves a database constraint (e.g. nullable) then the call fails due to a database constraint violation.

I've attached a sample project to illustrate. Create a Thing instance and then edit it. Set the name to NULL, which forces the value to null since empty form fields are blank, not null. Rather than validating the instance and logging the messages, you'll get an error page with the error

org.springframework.dao.DataIntegrityViolationException:
not-null property references a null or transient value: Thing.name

I spent some time debugging this a while back and it looks like the call to the services getMetaClass() ends the transaction and triggers a flush, so the call to thingService.saveThing() never actually executes - you can see that from the console log messages.

I saw this in a 1.0.4 app and it's a problem in 1.1, but I haven't tested in 1.0.5.



Burt Beckwith added a comment - 11/Apr/09 11:49 AM

Graeme Rocher added a comment - 22/Apr/09 07:54 AM

Calling getMetaClass() now longer causes a transaction to be started


Jan Rudert added a comment - 27/Jul/09 04:54 AM

Calling getMetaClass() now longer causes a transaction to be started

Could you please double check? I am using Grails 1.1.1 and I am seeing that TransactionService.getMetaClass() still opens a Transaction each time it is called.


Jan Rudert added a comment - 27/Jul/09 05:12 AM

Forget my comment, we replaced the responsible code from the ServiceGrailsPlugin with the code from 1.1 because of GRAILS-4644 which occured in 1.1.1. That's why we cannot enjoy the fix for this one here.