tags:

views:

460

answers:

4

Hi,

I'm getting "org.springframework.dao.DataIntegrityViolationException: not-null property references a null or transient value: A.b" exception on web flow in grails 1.1.2. there is

class B {
   ...
   static belongsTo = [a:A]
   ...
}

and

class A {
   ...
   static hasMany = [b:B]
   ...
}

Does anyone know what is wrong? Thanks Tom

+1  A: 

This is really going to depend most on what your parameters are and how you're handling creation or maintenance of the GORM objects, not your actual object graph.

John Stoneham
A: 

Agree with @John. One of the common solutions is, you should be saving the object as

a.addToB(b)
a.save()

Hope it helps.

Satya
A: 

Solved.

There was a different problem. I wasn't persisting anything. There appeared some inconsistences between serialized data in the flow and persisted data in the database. So a select query caused this exception.

Tomik
A: 

This problem is related to the ORM (I guess you are using hibernate below). The problem will be solved if you configure the cascade property of the mapped attributes.

I don't know how to configure it in grails, but this doc of hibernate should help you to understand where the problem is: http://docs.jboss.org/hibernate/stable/entitymanager/reference/en/html/objectstate.html#objectstate-transitive

Neuquino