I am trying to persist, using JPL, My objects into a simple BDB. Problem is that If I try to store a subclass in the primary index I get an error (below).
The subclasses possess nothing at all different in terms of data but they are functionally different and I would like for the subclass to be the instance type marshalled. If I must, then the key can contain the class in question and I can instantiate it myself
Perhaps I need one index per subclass? But that doesn't seem right and certainly complicates the lookup process.
Example:
@Test
public void testStoreEntity() throws Exception {
Random r = new Random();
File directory = new File("C:\\Users\\chribong\\development\\code\\edifecs\\engineering\\platform\\icd-code-factory\\src\\test\\data\\" + r.nextInt(1000));
directory.mkdirs();
EnvironmentConfig envConfig = new EnvironmentConfig();
envConfig.setAllowCreate(true);
envConfig.setTransactional(true);
Environment env = new Environment(directory, envConfig);
StoreConfig storeConfig = new StoreConfig();
storeConfig.setAllowCreate(true);
storeConfig.setTransactional(true);
EntityStore store = new EntityStore(env, "PersonStore", storeConfig);
PrimaryIndex<Key,AbstractBdbIcdCode> index = store.getPrimaryIndex(Key.class,AbstractBdbIcdCode.class);
index.put(new AbstractBdbIcdCode(10,"foo", ICDCode.Type.DIAGNOSIS,".*"));
index.put(new BdbIcd10DiagnosisCode("A000")); // error here
// java.lang.IllegalArgumentException: Class could not be loaded or is not persistent
}
classes
@Entity
public class AbstractBdbIcdCode implements ICDCode {
@PrimaryKey
private Key pk;
protected String description;
protected Set<String> concepts = new TreeSet<>();
protected Set<String> antiConcepts = new TreeSet<>();
protected Set<String> similarConcepts = new TreeSet<>();
}
@Persistent
public class Key {
@KeyField(1)
private ICDCode.Type type;
@KeyField(2)
private int version;
@KeyField(3)
private String code;
public Key() {
}
}
public class BdbIcd10DiagnosisCode extends AbstractBdbIcdCode implements ICD10DiagnosisCode{
private transient String category;
private transient String etiology;
private transient String location;
private String laterality;
protected String extension;
}