无法使用JPA在具有继承类型single的抽象类中添加多对一映射

时间:2017-07-27 05:43:38

标签: java spring hibernate jpa inheritance

我有一个名为Shape的抽象类,还有三个名为Circle,Triangle和Rectangle的子类。我使用继承类型single来映射这些类。

@Entity
@Table(name = "shape")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "shape_type")
public abstract class Shape{
 public enum ShapeType {
        RECTANGLE,
        CIRCLE,
        TRIANGLE
    }

    @Column(name = "LENGTH")
    private String what;    

    @ManyToOne(fetch= FetchType.LAZY)
    @JoinColumn(name = "color_id")
    private Color color;

    public Color getColor() {
        return color;
    }

    public void setColor(Color color) {
        this.color = color;
    }

    //getters and setters 

}

@Entity
@DiscriminatorValue(value = "RECTANGLE")
public class Rectangle extends Shape {
//proerties
}

@Entity
@DiscriminatorValue(value = "CIRCLE")
public class Circle extends Shape {
//proerties
}

我的问题是,当我为属性“color”添加此getter方法时,我收到异常“无法启动bean documentationPluginsBootstrapper”;嵌套异常是com.google.common.util.concurrent.ExecutionError:java .lang.StackOverflowError

这是我得到的完整堆栈跟踪

 ERROR org.springframework.boot.SpringApplication - Application startup failed
    org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is com.google.common.util.concurrent.ExecutionError: java.lang.StackOverflowError
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:176)
        at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:51)
        at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:346)
        at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:149)
        at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:112)
        at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:879)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:372)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1187)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1176)
        at com.mvv.casat.SpringBootInitializer.main(SpringBootInitializer.java:22)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
    Caused by: com.google.common.util.concurrent.ExecutionError: java.lang.StackOverflowError
        at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2201)
        at com.google.common.cache.LocalCache.get(LocalCache.java:3937)
        at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3941)
        at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4824)
        at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4830)
        at springfox.documentation.spring.web.scanners.CachingOperationReader.read(CachingOperationReader.java:57)
        at springfox.documentation.spring.web.scanners.ApiDescriptionReader.read(ApiDescriptionReader.java:66)
        at springfox.documentation.spring.web.scanners.ApiListingScanner.scan(ApiListingScanner.java:89)
        at springfox.documentation.spring.web.scanners.ApiDocumentationScanner.scan(ApiDocumentationScanner.java:71)
        at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper.scanDocumentation(DocumentationPluginsBootstrapper.java:95)
        at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper.start(DocumentationPluginsBootstrapper.java:154)
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:173)
        ... 19 common frames omitted
    Caused by: java.lang.StackOverflowError: null
        at com.google.common.collect.Iterables.any(Iterables.java:623)
        at springfox.documentation.schema.WildcardType.hasWildcards(WildcardType.java:42)
        at springfox.documentation.schema.WildcardType$1.apply(WildcardType.java:83)
        at springfox.documentation.schema.WildcardType$1.apply(WildcardType.java:80)
        at com.google.common.collect.Iterators.indexOf(Iterators.java:778)
        at com.google.common.collect.Iterators.any(Iterators.java:684)
        at com.google.common.collect.Iterables.any(Iterables.java:623)
        at springfox.documentation.schema.WildcardType.hasWildcards(WildcardType.java:42)
        at springfox.documentation.schema.AlternateTypeRule.appliesTo(AlternateTypeRule.java:79)
        at springfox.documentation.spi.schema.AlternateTypeProvider$1.apply(AlternateTypeProvider.java:57)
        at springfox.documentation.spi.schema.AlternateTypeProvider$1.apply(AlternateTypeProvider.java:54)
        at com.google.common.collect.Iterators$7.computeNext(Iterators.java:652)
        at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:143)
        at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:138)
        at com.google.common.collect.Iterators.tryFind(Iterators.java:752)
        at com.google.common.collect.Iterables.tryFind(Iterables.java:675)
        at com.google.common.collect.FluentIterable.firstMatch(FluentIterable.java:236)
        at springfox.documentation.spi.schema.AlternateTypeProvider.alternateFor(AlternateTypeProvider.java:41)
        at springfox.documentation.spring.web.readers.parameter.ModelAttributeParameterExpander.fieldType(ModelAttributeParameterExpander.java:256)
        at springfox.documentation.spring.web.readers.parameter.ModelAttributeParameterExpander.access$100(ModelAttributeParameterExpander.java:61)
        at springfox.documentation.spring.web.readers.parameter.ModelAttributeParameterExpander$9.apply(ModelAttributeParameterExpander.java:228)
        at springfox.documentation.spring.web.readers.parameter.ModelAttributeParameterExpander$9.apply(ModelAttributeParameterExpander.java:225)
        at com.google.common.collect.Iterators$8.transform(Iterators.java:799)
        at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:48)
        at com.google.common.collect.Iterators$7.computeNext(Iterators.java:651)
        at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:143)
        at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:138)
        at com.google.common.collect.Iterators$7.computeNext(Iterators.java:650)
        at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:143)
        at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:138)
        at springfox.documentation.spring.web.readers.parameter.ModelAttributeParameterExpander.expand(ModelAttributeParameterExpander.java:88)

一旦我删除了颜色属性的getter方法,它就可以正常工作了。我通过互联网搜索但无法找到答案。  任何人都可以帮我解决这个问题吗?

0 个答案:

没有答案