0
我Entity
模樣JPA:@Embedded實體如何將自己的類型作爲字段?
@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)
這究竟是爲什麼以及如何解決這個問題?
我明白了,謝謝@Mikko,但是我可以通過'JPA'擁有包含'parentVersion'的'version'的方式是什麼? – daydreamer 2013-02-10 18:27:12
通常在這種情況下,版本是實體,並且具有ManyToOne關係自身(從小孩到父母)。如果需要雙向關係,則另外OneToMany(集合值)向其他方向。 – 2013-02-10 18:34:26