Reputation: 56944
I have the following entity:
@Entity("platform_defs")
class PlatformDef {
@Id
Long id
@Property("name")
String name
@Property("abbreviation")
String abbreviation
@Property("type")
String type
@Property("hg_repo")
String hgRepo
@Property("port")
Long port
@Property("status")
String status
}
And the following Morphia code trying to persist an instance of that entity:
public void savePlatformDef(PlatformDef pDef) {
try {
AppConfig config = getConfig();
String dbName = config.getMongo().getDatabaseName();
Mongo mongo = new Mongo(config.getMongo().getHost(), config.getMongo().getPort());
morphia = new Morphia();
datastore = morphia.createDatastore(mongo, dbName);
morphia.map(PlatformDef.class);
datastore.save(pDef);
} catch(Throwable t) {
System.out.println(t.getMessage());
}
}
When I run this I get:
java.lang.StackOverflowError
Here is the recursive list of calls being made:
at org.mongodb.morphia.mapping.EmbeddedMapper(toDBObject:40)
at org.mongodb.morphia.mapping.Mapper(writeMappedField:642)
at org.mongodb.morphia.mapping.Mapper(toDBObject:544)
at org.mongodb.morphia.mapping.Mapper(toDBObject:526)
This pattern repeats over and over again... What's wrong with my setup?
Upvotes: 1
Views: 964
Reputation: 6459
Probably too late to help you, but I ran into this issue as well. I can't tell from what you provided code wise, but most likely your using an anonymous inner class at some point in the construction of the platformDef you pass to your savePlatformDef method. Apparently morphia does not support anonymous inner classes, they are known to cause stack overflows just like this. See this bug for detail:
https://github.com/mongodb/morphia/issues/402
Hopefully this answer will help others like me in the future :)
Upvotes: 0
Reputation: 10859
@Id
MongoClient
instead of Mongo
, which is deprecated / already removed depending on your version of Mongo Java driverUpvotes: -1