java.lang.InstantiationException when trying to find a class that extends a abstract class.
See original GitHub issueI created something like this below:
@Entity public abstract class myabs { }
public class child extends myabs { }
when I tried to find using the code like below:
new AnonymousClass { public void find() {
Mongo mongo ...
Morphia mor ...
...
List<ObjectId>ids = dao.findIds();
Model model = null;
for(ObjectId id : ids)
model = dao.get(id);
} }
I got the exception:
java.lang.RuntimeException: java.lang.RuntimeException at org.mongodb.morphia.mapping.EmbeddedMapper.fromDBObject(EmbeddedMapper.java:161) at org.mongodb.morphia.mapping.Mapper.readMappedField(Mapper.java:604) at org.mongodb.morphia.mapping.Mapper.fromDb(Mapper.java:584) at org.mongodb.morphia.mapping.Mapper.fromDBObject(Mapper.java:294) at org.mongodb.morphia.query.MorphiaIterator.convertItem(MorphiaIterator.java:71) at org.mongodb.morphia.query.MorphiaIterator.processItem(MorphiaIterator.java:58) at org.mongodb.morphia.query.MorphiaIterator.next(MorphiaIterator.java:53) at org.mongodb.morphia.query.QueryImpl.get(QueryImpl.java:408) at org.mongodb.morphia.DatastoreImpl.get(DatastoreImpl.java:606) at org.mongodb.morphia.dao.BasicDAO.get(BasicDAO.java:165) at controllers.CityController$1$1.invoke(CityController.java:77) at controllers.CityController$1$1.invoke(CityController.java:37) at play.core.j.JavaWebSocket$$anonfun$webSocketWrapper$1$$anonfun$apply$1$$anonfun$apply$2$$anonfun$apply$3.apply(JavaWebSocket.scala:43) at play.core.j.JavaWebSocket$$anonfun$webSocketWrapper$1$$anonfun$apply$1$$anonfun$apply$2$$anonfun$apply$3.apply(JavaWebSocket.scala:43) at scala.collection.Iterator$class.foreach(Iterator.scala:727) at scala.collection.AbstractIterator.foreach(Iterator.scala:1157) at scala.collection.IterableLike$class.foreach(IterableLike.scala:72) at scala.collection.AbstractIterable.foreach(Iterable.scala:54) at play.core.j.JavaWebSocket$$anonfun$webSocketWrapper$1$$anonfun$apply$1$$anonfun$apply$2.apply(JavaWebSocket.scala:43) at play.core.j.JavaWebSocket$$anonfun$webSocketWrapper$1$$anonfun$apply$1$$anonfun$apply$2.apply(JavaWebSocket.scala:43) at play.api.libs.iteratee.Iteratee$$anonfun$foreach$1.apply(Iteratee.scala:198) at play.api.libs.iteratee.Iteratee$$anonfun$foreach$1.apply(Iteratee.scala:198) at play.api.libs.iteratee.Iteratee$$anonfun$fold$1$$anonfun$apply$1.apply(Iteratee.scala:38) at play.api.libs.iteratee.internal$.eagerFuture(package.scala:27) at play.api.libs.iteratee.Iteratee$$anonfun$fold$1.apply(Iteratee.scala:38) at play.api.libs.iteratee.Iteratee$$anonfun$fold$1.apply(Iteratee.scala:38) at play.api.libs.iteratee.Iteratee$$anonfun$1.apply(Iteratee.scala:57) at play.api.libs.iteratee.Iteratee$$anonfun$1.apply(Iteratee.scala:57) at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) at scala.concurrent.forkjoin.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1361) at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) Caused by: java.lang.RuntimeException at org.mongodb.morphia.mapping.DefaultCreator.createInst(DefaultCreator.java:127) at org.mongodb.morphia.mapping.DefaultCreator.createInstance(DefaultCreator.java:31) at org.mongodb.morphia.mapping.DefaultCreator.createInstance(DefaultCreator.java:42) at org.mongodb.morphia.mapping.DefaultCreator.createInstance(DefaultCreator.java:54) at org.mongodb.morphia.mapping.EmbeddedMapper.readMapOrCollectionOrEntity(EmbeddedMapper.java:246) at org.mongodb.morphia.mapping.EmbeddedMapper.readCollection(EmbeddedMapper.java:191) at org.mongodb.morphia.mapping.EmbeddedMapper.fromDBObject(EmbeddedMapper.java:135) … 34 more Caused by: java.lang.InstantiationException at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:30) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at org.mongodb.morphia.mapping.DefaultCreator.createInst(DefaultCreator.java:125) … 40 more
Issue Analytics
- State:
- Created 10 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
I’m assuming this worked for you. I’ll close this in a few days if I haven’t heard back.
That abstract class is going to break things because it can’t be instantiated so it needs to be not abstract. To fix your queries to correctly return the Child class do something like this:
datastore.createQuery(Child.class).filter("className = ", Child.class.getName()) …
That should resolve both issues for you.
On Tue, Oct 15, 2013 at 8:25 PM, Abraão Isvi notifications@github.comwrote: