Bar와 양방향 일대일 관계가 있고 Baz와는 양방향 일대일 관계가있는 객체 Foo가 있습니다. Foo로 .load를 수행하려고 할 때 Bar에게만 줄 것을 요청하면 Baz가 없다는 불평하는 참조 무결성 예외가 발생합니다.Fixtures Plugin 참조 무결성 예외 Grails에서
이 경우가 좋을까요? 실제 환경에서는 데이터베이스에 일치하는 Baz 객체가 없을 가능성이 있습니까?
필자는 fixtures로드 클로저에서 수동으로 baz : null 설정을 시도했지만 여전히 동일한 결과를 얻습니다. 부가 메모에서 속성 (예 : 간단한 문자열) 만 설정하면 모든 것이 올바르게 작동합니다. 그것은 내가 관계를 설정하기 시작할 때뿐입니다.
이것은 Grails 2.2.4, Fixtures 1.2 및 build-test-data plugin이 설치되어 있지 않은 것입니다.
EDIT : Baz를 null 허용 및 고유하게 지정하는 제약이 있습니다. 단지 킥킥 웃음을 위해서 나는 blank
제약 조건을 추가하려했지만 행운은 없었다.
static constraints = {
baz nullable:true, unique: true, blank: true
}
EDIT 2는 : org.h2.jdbc :
의해 발생 :
class Foo { String someValue1 String someValue2 String whatever Bar bar Baz baz static mapping = { id composite: ['someValue1', 'someValue2'], generator: 'assigned' columns { bar([:]) { column name: 'some_other_value' } baz ([insertable:false, updateable: false]) { column name: 'some_value_1' column name: 'some_value_2' } } version: false static constraints = { //there are no constraints for Bar baz nullable:true, unique:true } } class Bar { String someOtherValue static hasMany = [foos:Foo] static mapping = { id generator:'assigned', name:'someOtherValue' } } class Baz { String someValue1 String someValue2 String asdf static mapping = { id composite: ['some_value_1', 'some_value_2'] version false } } class MyTest { def fixtureLoader @Before void setup() { fixureLoader.load { myBar(Bar, someOtherValue:"shibby") myFoo(Foo, someValue1:"test", someValue2:"test2", bar:myBar) //i also tried this //myFoo(Foo, someValue1:"test", someValue2:"test2", bar:myBar, baz:null) } } }
여기 예외의 일부이다 : 다음 코드의 간략화 된 버전이다. JdbcBatchUpdateException : 참조 무결성 제약 조건 위반 : "FK190E74B120F4F2BC : MYSCHEMA.FOO 외래 KEY (SOME_VALUE_1, SOME_VALUE_2) 참조 SCHEMA.BAZ (SOME_VALUE_1, SOME_VALUE_2) "; SQL 문 : (????????,,,,, ,,) (무엇이든, some_other_value, some_value_2, some_value_1) 값 MYSCHEMA.foo에 삽입 [23506-164]
편집 : 죄송합니다. 일찍 발표하지 못했습니다. Bar는 Foo와 다 대일 관계를 맺고 있습니다.
간단한 실패 사례를 게시 할 수 있습니까? 도메인 클래스 및 픽스쳐가 도움이 될 것입니다. –
좋아, 방금 게시했습니다. –
Bar에 ID가 'generator :'assigned''로 설정되어 있지만 ID 값이 어디에도 설정되어 있지 않습니다. Bar가 저장 실패로 인해 Foo를 저장할 때 참조 무결성 제약 조건을 유발합니까? – proflux