Grails

validate() method is not called upon session.flush()

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Won't Fix
  • Affects Version/s: 1.0.1
  • Fix Version/s: 1.0.2
  • Component/s: None
  • Labels:
    None
  • Environment:
    Linux/WinXP, Eclipse 3.3+

Description

The injected validation() method of a domain class is called only, when the injected save() or update() methods are called.

If none of Grails' dynamic methods is called explicitly, then validation() is not performed upon hibernate's session flushing / TX's commit.
Instead, the low-level DB's constraint-violation exceptions are thrown, and they are more difficuilt to catch.

Example:

class MyController{
def updateAttribute = { def attribute = Attribute.get( params.id ) attribute.nameToken = params.nameToken render( template:'attribute', model:[ attributes:(category.attributes) ] ) }
}

It shall be possible to call the Grails validation on "before-update/insert" automatically, and populate errors object and eventully delegate to a certain error-handler

Activity

Hide
Graeme Rocher added a comment -

This is by design, the solution is always to call save()

Show
Graeme Rocher added a comment - This is by design, the solution is always to call save()

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: