我試圖使用地圖作爲我的模型屬性之一的類型。讓我們以這兩類爲例:使用地圖作爲遊戲中的模型屬性
@Entity
public class Foo extends Model {
@OneToMany(mappedBy = "foo", cascade = CascadeType.ALL)
@MapKey(name = "name")
public Map<String, Bar> bars;
public String name;
}
@Entity
public class Bar extends Model {
@ManyToOne
public Foo foo;
public String name;
}
當然非常簡化,但這是基本的想法。 所以我試圖實現的是獲得一個帶有Bars的地圖作爲值和名稱作爲它們到Foo的鍵。
現在我想利用夾具從這個YAML文件中加載一些數據:
Foo(foo1):
name: Foo1
Foo(foo2):
name: Foo2
Bar(bar1):
name: Bar1
foo: foo1
Bar(bar2):
name: Bar2
foo: foo1
沒有問題,到目前爲止,這個工程就像一個魅力。現在,如果我試圖改變BAR2到foo: foo2
,我得到這個異常:
play.exceptions.JavaExecutionException: Cannot load fixture initial-data.yml: org.hibernate.HibernateException: Found two representations of same collection: models.Foo.bars
at play.jobs.Job.call(Job.java:166)
at Invocation.Job(Play!)
Caused by: java.lang.RuntimeException: Cannot load fixture initial-data.yml: org.hibernate.HibernateException: Found two representations of same collection: models.Foo.bars
at play.test.Fixtures.loadModels(Fixtures.java:221)
at jobs.Bootstrap.doJob(Bootstrap.java:18)
at play.jobs.Job.doJobWithResult(Job.java:55)
at play.jobs.Job.call(Job.java:157)
... 1 more
Caused by: javax.persistence.PersistenceException: org.hibernate.HibernateException: Found two representations of same collection: models.Foo.bars
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1214)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1147)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1153)
at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:798)
at play.db.jpa.JPABase._save(JPABase.java:47)
at play.test.Fixtures.loadModels(Fixtures.java:205)
... 4 more
Caused by: org.hibernate.HibernateException: Found two representations of same collection: models.Foo.bars
at org.hibernate.engine.Collections.processReachableCollection(Collections.java:175)
at org.hibernate.event.def.FlushVisitor.processCollection(FlushVisitor.java:60)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:122)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:83)
at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:77)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:165)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:240)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:795)
... 6 more
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:795)
... 6 more
當然我試圖谷歌,但找不到我的情況下,任何解決方案。有關於此的任何想法?有趣的是,我可以去改變數據庫中的值,然後將bar2分配給foo1,它的工作原理完全正常,所以我不能錯...
幫助將不勝感激:)
最佳, kalarzo
你可以嘗試發佈這個問題來發揮框架谷歌組http://groups.google.com/group/play-framework,他們是非常敏感的... – opensas 2011-09-18 16:10:38
我問這個「非常相似」 - 相同的問題[這裏](http://stackoverflow.com/questions/8508068/how-to-debug-found-two-representations-of-same-collection)。看看[對我有用](http://stackoverflow.com/a/8521408/11236)。 – ripper234 2011-12-15 21:03:13