J'essaie d'utiliser une carte comme type pour l'une de mes propriétés de modèle. Prenons ces deux classes par exemple:Utiliser Map comme propriété du modèle dans Play
@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;
}
Très simplifié bien sûr, mais c'est l'idée de base. Donc, ce que j'essaie de faire est d'obtenir une carte avec des valeurs comme barres et les noms comme leurs clés dans Foo.
Maintenant, je veux utiliser Fixture pour charger des données de ce fichier YAML:
Foo(foo1):
name: Foo1
Foo(foo2):
name: Foo2
Bar(bar1):
name: Bar1
foo: foo1
Bar(bar2):
name: Bar2
foo: foo1
Pas de problème jusqu'à présent, cela fonctionne comme un charme. Maintenant, si je tente de changer bar2 à foo: foo2
, je reçois cette exception:
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
Bien sûr, j'essayé de google mais n'a pas pu trouver une solution pour mon cas. Des idées là-dessus? Curieusement, je peux aller et changer les valeurs dans la base de données et ensuite attribuer bar2 à foo1 et tout fonctionne parfaitement bien, donc je ne peux pas être trop mal ...
aide serait appréciée :)
Best, kalarzo
Vous pouvez essayer de poster cette question pour jouer à google group framework sur http://groups.google.com/group/play-framework, ils sont très réactifs ... – opensas
J'ai posé cette question "très similaire" - identique [ ici] (http://stackoverflow.com/questions/8508068/how-to-debug-found-two-representations-of-same-collection). Découvrez [ce qui a fonctionné pour moi] (http://stackoverflow.com/a/8521408/11236). – ripper234