0

我的Entity样子

@Entity
public class Market extends MutableEntity {

    @Column(nullable = false)
    private String name;
    @Column
    private String description;
    @Embedded
    private Version marketVersion; ..snipped

其中@Embedded Version

@Embeddable
public class Version {
    private String number;
    private VersionType versionType;
    private DateTime publishedOn;
    private DateTime retiredOn;
    private Version parentVersion;

但这失败了

08:12:23.481 [main] DEBUG o.h.cfg.annotations.PropertyBinder - Building property number
08:12:23.481 [main] DEBUG org.hibernate.cfg.Ejb3Column - Binding column: Ejb3Column{table=org.hibernate.mapping.Table(Market), mappingColumn=parentVersion, insertable=true, updatable=true, unique=false}

    java.lang.StackOverflowError
        at org.hibernate.cfg.AbstractPropertyHolder.getExactOverriddenColumn(AbstractPropertyHolder.java:179)
        at org.hibernate.cfg.AbstractPropertyHolder.getExactOverriddenColumn(AbstractPropertyHolder.java:179)
        at org.hibernate.cfg.AbstractPropertyHolder.getExactOverriddenColumn(AbstractPropertyHolder.java:179)
        at org.hibernate.cfg.AbstractPropertyHolder.getExactOverriddenColumn(AbstractPropertyHolder.java:179)
        at org.hibernate.cfg.AbstractPropertyHolder.getExactOverriddenColumn(AbstractPropertyHolder.java:179)
        at org.hibernate.cfg.AbstractPropertyHolder.getExactOverriddenColumn(AbstractPropertyHolder.java:179)
        at org.hibernate.cfg.AbstractPropertyHolder.getExactOverriddenColumn(AbstractPropertyHolder.java:179)
        at org.hibernate.cfg.AbstractPropertyHolder.getExactOverriddenColumn(AbstractPropertyHolder.java:179)
        at org.hibernate.cfg.AbstractPropertyHolder.getExactOverriddenColumn(AbstractPropertyHolder.java:179)

为什么会发生这种情况,我该如何解决这个问题?

4

1 回答 1

5

那是做不到的。此外,支持这样的结构也没有太大意义,因为没有任何包含结束的点:Version包含Version、包含Version、包含Version等。

在 JPA 2.0 规范中,这是用以下词语来说明的:

不允许可嵌入类之间的直接或间接循环包含依赖关系。

于 2013-02-10T18:14:54.790 回答