Grails

2011-08-11 23 views
6

0 के पास विरासत मैपिंग के साथ मेरे पास 4 कक्षा ए, बी, बी 1, बी 2 है:
ए (तालिका ए में मैप किया गया) शीर्ष-सबसे अभिभावक वर्ग है और इसकी विरासत मैपिंग रणनीति है tablePerHierarchy=false (इसका मतलब है कि इसके प्रत्येक उप-वर्ग को एक ही तालिका में मैप किया गया है)।
कक्षा बी ए से फैली हुई है, और बी 1, बी 2 बी से फैली हुई है लेकिन बी 1 और बी 2 बी के साथ एक ही टेबल साझा करते हैं, इसलिए बी कक्षा में, मैं tablePerHierarchy=true और बी 1 और बी 2 को अलग करने के लिए एक भेदभावकर्ता घोषित करता हूं।
विस्तार कोड यहाँ है:Grails

class A { 
    static mapping = { 
      tablePerHierarchy false 
      table 'A' 
    } 
} 

class B extends A { 
    static mapping = { 
      tablePerHierarchy true 
      table 'B' 
      discriminator column : 'TYPE' 
    } 
    String bProp1 
    String bProp2 
} 

class B1 extends B { 
    static mapping = { 
      discriminator column : 'TYPE', value : 'B1' 
    } 
    String b1Props1 
    String b1Props2 
} 

class B2 extends B { 
    static mapping = { 
      discriminator column : 'TYPE', value : 'B2' 
    } 
    String b2Props1 
    String b2Props1 
} 

मेरे एप्लिकेशन शुरू करते हैं, वहाँ एक त्रुटि हुई:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: No discriminator found for edu.test.B1. Discriminator is needed when 'single-table-per-hierarchy' is used and a class has subclasses 
    at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:212) 
    at grails.web.container.EmbeddableServer$start.call(Unknown Source) 
    at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:158) 
    at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy) 
    at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:280) 
    at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy) 
    at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149) 
    at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy) 
    at _GrailsRun_groovy.runInline(_GrailsRun_groovy:116) 
    at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy) 
    at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59) 
    at RunApp$_run_closure1.doCall(RunApp:33) 
    at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381) 
    at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415) 
    at gant.Gant$_dispatch_closure7.doCall(Gant.groovy) 
    at gant.Gant.withBuildListeners(Gant.groovy:427) 
    at gant.Gant.this$2$withBuildListeners(Gant.groovy) 
    at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source) 
    at gant.Gant.dispatch(Gant.groovy:415) 
    at gant.Gant.this$2$dispatch(Gant.groovy) 
    at gant.Gant.invokeMethod(Gant.groovy) 
    at gant.Gant.executeTargets(Gant.groovy:590) 
    at gant.Gant.executeTargets(Gant.groovy:589) 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: No discriminator found for edu.test.B1. Discriminator is needed when 'single-table-per-hierarchy' is used and a class has subclasses 
    ... 23 more 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: No discriminator found for edu.test.B1. Discriminator is needed when 'single-table-per-hierarchy' is used and a class has subclasses 
    ... 23 more 
Caused by: org.hibernate.MappingException: No discriminator found for edu.test.B1. Discriminator is needed when 'single-table-per-hierarchy' is used and a class has subclasses 
    ... 23 more 

मैं discriminator (http://grails.org/doc/latest/ref/Database%20Mapping/discriminator.html) के बारे में Grails प्रलेखन के निर्देश का पालन किया है, लेकिन उसने ऐसा नहीं किया काम। मुझे यहां इस दस्तावेज़ मुद्दे के बारे में एक जिरा मिला है: http://jira.grails.org/browse/GRAILS-5168 और मेरे कोड को ठीक करते हुए ठीक किया लेकिन यह अभी भी एक ही त्रुटि है।

मुझे इस कारण के कारण के बारे में पता नहीं है। क्या tablePerHierarchy = बी में सत्य उस ए में परिभाषित रणनीति को ओवरराइड करता है?
क्या आप कृपया इस समस्या को ठीक करने में मेरी मदद कर सकते हैं? बहुत बहुत धन्यवाद।

+0

आपको स्वीकृत उत्तरों को चिह्नित करना चाहिए – dbrin

उत्तर

1

ऐसा लगता है कि कक्षा पदानुक्रम के लिए विरासत रणनीतियों को मिलाकर वास्तव में जेपीए/हाइबरनेट स्तर तक भी समर्थित नहीं है। मुझे लगता है कि आपकी समस्या का (या कम से कम बहुत समान करने के लिए) ये एक ही है:

Changing the inheritance strategy in branches of the class hierarchy via JPA annotations

How to mix inheritance strategies with JPA annotations and Hibernate?

आप 'org.codehaus.groovy.grails.orm के लिए लॉगिंग सेटिंग परिवर्तित करते हैं .bernernate 'to' डीबग 'आप देख सकते हैं कि कक्षा बी में' tablePerHierarchy = true 'सेटिंग ए में रणनीति को ओवरराइड नहीं करती है, भले ही यह काम न करे। फिर, यह गोरम की तुलना में निचले स्तर पर एक सीमा है। उस पदानुक्रम के लिए एक विरासत रणनीति का उपयोग करने के लिए अपने डिजाइन को संशोधित कर सकते हैं?