Hello all,
First of all congratulations to Play framework and all its community.
We've been using Play for a couple of months on a project and it's
been really great overall.
We are now migrating our model from MySQL to MongoDB, and we have
chosen to go with Morphia for its convenience and similarity to JPA.
However, we are having a problem I will try to exemplify.
We have class Content as follows:
@Entity("content")
public abstract class Content extends Model {
@Required
public String description;
@Required
public Date date;
public Content(String description, Date date) {
this.description = description;
this.date = date;
}
}
And we have another class ContentChild which is a "child" of Content
adding some more fields. This class is to be stored in the same
collection as Content.
@Entity("content")
public class ContentChild extends Content {
@Required
public int type;
@Required
public String item;
public ContentChild(String description, Date date, int type,
String item) {
super(description, date);
this.type = type;
this.item = item;
}
}
Now each time I run the app, I get a lot of errors like the following:
com.google.code.morphia.mapping.validation.ConstraintViolationException:
Number of violations: 2
MultipleId complained about models.ContentChild. : More than one @Id
Field found (_id, _id).DuplicatedAttributeNames complained about
models.ContentChild._id : Mapping to MongoDB field name '_id' is
duplicated; you cannot map different java fields to the same MongoDB
field.
at
com.google.code.morphia.mapping.validation.MappingValidator.validate(MappingValidator.java:
65)
at
com.google.code.morphia.mapping.validation.MappingValidator.validate(MappingValidator.java:
153)
at
com.google.code.morphia.mapping.MappedClass.validate(MappedClass.java:
259)
at com.google.code.morphia.mapping.Mapper.addMappedClass(Mapper.java:
152)
at com.google.code.morphia.mapping.Mapper.addMappedClass(Mapper.java:
140)
at com.google.code.morphia.Morphia.map(Morphia.java:55)
at play.modules.morphia.MorphiaPlugin.configureDs_(MorphiaPlugin.java:
174)
at
play.modules.morphia.MorphiaPlugin.onApplicationStart(MorphiaPlugin.java:
154)
at play.Play.start(Play.java:427)
at play.Play.detectChanges(Play.java:543)
at play.Invoker$Invocation.init(Invoker.java:100)
at Invocation.HTTP Request(Play!)
and in the end:
RuntimeException:
too many errories mapping Morphia Entity classes
I noticed that there's a similar error with Morphia Grails module
(link through Google Cache):
http://webcache.googleusercontent.com/search?q=cache:n-2Vrxt6clEJ:jira.codehaus.org/browse/GRAILSPLUGINS-2895%3Fpage%3Dcom.atlassian.jira.plugin.system.issuetabpanels%253Achangehistory-tabpanel+mongodb+%22MultipleId+complained+about%22&cd=2&hl=en&ct=clnk&source=www.google.com
But Morphia alone is supposed to work well in this scenario, as
referenced in their Wiki (look at the animals example):
http://code.google.com/p/morphia/wiki/EntityAnnotation
Any clues on how to solve this problem?
Thanks!
paulo