-
Jun 1st, 2011, 05:09 AM
#1
Grails delete bidirectional association
Hi all,
I want to create bidirectional one to one association,
so I have created following domain classes and controllers:
class Face {
String val11
String val12
static hasOne = [nose: Nose]
static constraints = {
nose(nullable:true)
}
}
class Nose {
Face face
String val21
String val22
static constraints = {
face(nullable:true)
}
}
class FaceController {
static transactional = false
def create = {
def face = new Face()
def nose = Nose.get(params.nose)
if(nose!=null){
face.properties = params
face.nose = nose
face.save(flush: true)
nose.face = face
nose.save(flush:true)
} else{
face.properties = params
face.save(flush: true)
}
String strJson = (face as JSON)
render strJson
}
def remove = {
Face face = Face.findById(params.id)
face.delete(flush: true)
render params.id
}
}
class NoseController {
static transactional = false
def create = {
def nose = new Nose()
nose.properties = params
nose.save(flush: true)
String strJson = (nose as JSON)
render strJson
}
def remove = {
Nose nose = Nose.findById(params.id)
nose.delete(flush: true)
render params.id
}
}
I can successfully create nose and after it face objects, and can get nose value through face (Face.get(1).nose) and face value through nose (Nose.get(1).face).
My problem is when I want to delete objects(for example face), I got the following exception:
org.springframework.dao.DataIntegrityViolationExce ption: Foreign key constraint violation trying to delete onetoone.Nose with id 1
at org.grails.hbase.gorm.DeletePersistentMethod.invok e(DeletePersistentMethod.groovy:66)
---------------------------------------------------------------------------
I have tried before deleting face explicity set nose to null:
//in FaceController
def remove = {
Face face = Face.findById(params.id)
Nose nose = Nose.findById(face.nose.id)
face.nose = null
nose.face = null
nose.save(flush:true)
face.save(flush:true)
face.delete(flush: true)
render params.id
}
After this I can delete face, but in any case in my cosole it throw the following exception:
ERROR gorm.SavePersistentMethod - Cannot get property 'class' on null object
java.lang.NullPointerException: Cannot get property 'class' on null object
at org.codehaus.groovy.runtime.NullObject.getProperty (NullObject.java:56)
at org.codehaus.groovy.runtime.InvokerHelper.getPrope rty(InvokerHelper.java:156)
-----------------------------------------------------------------------------
ERROR associations.ReferenceTable - Reference table entry not found, row=[79, 78, 69, 84, 79, 79, 78, 69, 95, 79, 78, 69, 84, 79, 79, 78, 69, 95, 78, 79, 83, 69, 95, 0, 0, 0, 0, 0, 0, 0, 1]
I use grails-1.3.2 and gorm-hbase-0.2.4.
Please say what am I doing wrong?
If anybody know solution please help..
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules