Okay, that's correct. When i tested with production entities it really
does work perfectly. But still, with my test code, i am not able to get
object stored to db - db.Test.findOne() just gets null. It must be that
there is some error in my test code, i will attach it here as it now is
@Entity
public abstract class ModelObject implements Serializable {
@Id private String id = new ObjectId().toString();
private Date created = new Date();
@Version private long modified;
// accessors + toString...
}
@Entity("testentity")
public class TestEntity extends ModelObject {
private int test = 12345;
// accessors + toString
}
public class Test {
public static void main(String[] args) throws Exception {
Mongo connection = new Mongo();
Morphia morphia = new Morphia();
morphia.map(TestEntity.class);
Datastore ds = morphia.createDatastore(connection, "test_db");
BasicDAO<TestEntity, String> dao = new BasicDAO<TestEntity, String>(TestEntity.class, ds);
TestEntity entity = new TestEntity();
dao.save(entity);
System.out.println("should be saved = "+entity);
}
}
after running this, and in mongo: use test_db; db.testentity.findOne(); gets null. But if I change TestEntity to not inherit from ModelObject and give it own @Id private String id = new ObjectId().toString(); then it will save to db_test.testentity. So i am little confused, inheritance works with real entities but not with above test code.