hibernate - Storing and retrieving copmosit objects in Java -
i have more 2 classes have approximately 7 same fields , following in java part:
public abstract class ibase { private string commonfield1; private string commonfield2; private string commonfield3; private emytype type; // type of object: my_type_1 or my_type_2 // ... // + constructor , getters/setters } public class baseimpl1 extends ibase { private int base1specific1; private int base1specific2; // ... // + constructor , getters/setters } public class baseimpl2 extends ibase { private int base2specific; private string base2specific2; // ... // + constructor , getters/setters }
i have 2 questions:
- what best way reflect 2 object within database?
- how should retrieve them via hibernate?
using morphia, you'd mark interface @entity(somecollectionname). when you're querying types, have datastore.createquery(baseimpl1.class).filter("classname = ", baseimpl1.class.getname()) retrieve particular subclass.
Comments
Post a Comment