Grails “not-null property references a null or transient value” exception on web flow

StackOverflow https://stackoverflow.com/questions/2045855

  •  20-09-2019
  •  | 
  •  

Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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.

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

a.addToB(b)
a.save()

Hope it helps.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top