I have the following class:
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class TclRequest implements Comparable<TclRequest> {
@PrimaryKey
private String id;
@Persistent(types = { DNSTestData.class, POP3TestData.class, PPPoETestData.class, RADIUSTestData.class }, defaultFetchGroup = "true")
@Columns({ @Column(name = "dnstestdata_fk"), @Column(name = "pop3testdata_fk"), @Column(name = "pppoetestdata_fk"), @Column(name = "radiustestdata_fk") })
private TestData testData;
public String getId() {
return id;
}
public TestData getTestData() {
return testData;
}
public void setId(String id) {
this.id = id;
}
public void setTestData(TestData testData) {
this.testData = testData;
}
}
The TestData interface looks like this:
@PersistenceCapable(detachable = "true")
public interface TestData {
@PrimaryKey
public String getId();
public void setId(String id);
}
Which is implemented by many classed including this one:
@PersistenceCapable(detachable = "true")
public class RADIUSTestData implements TestData {
@PrimaryKey
private String id;
private String password;
private String username;
public RADIUSTestData() {
}
public RADIUSTestData(String password, String username) {
super();
this.password = password;
this.username = username;
}
@Override
public String getId() {
return id;
}
@Override
public void setId(String id) {
this.id = id;
}
}
When I try to persiste the TclRequest class, after constructing it of course and using the RADIUSTestData:
//'o' is the constructed TclRequest object.
PersistenceManager pm = null;
Transaction t = null;
try {
pm = getPM();
t = pm.currentTransaction();
t.begin();
pm.makePersistent(o);
t.commit();
} catch (Exception e) {
e.printStackTrace();
if (t != null && t.isActive()) {
t.rollback();
}
} finally {
closePM(pm);
}
The interface field isn’t persisted. And the column is not created in the table ! I enabled the debug mode and found 2 catchy things:
1)
-Class com.skycomm.cth.beans.ixload.radius.TestData specified to use “application identity” but no “objectid-class” was specified. Reverting to javax.jdo.identity.StringIdentity
2)
-Performing reachability on PC field “com.skycomm.cth.beans.TclRequest.testData”
-Could not find StateManager for PC object “” at field “com.skycomm.cth.beans.TclRequest.testData” – ignoring for reachability
What could this mean ?
Thanks in advance.
I have figured out how to do it. It’s not very much scalable but it works for now.
These are the annotations for the interface member variable. Note that the order of declared types, columns and class names in the extension value is important to be maintaned:
A sample class implementing one of the interfaces (Just it’s “header”):
So it’s pretty normal here.