datanucleus-core
datanucleus-core copied to clipboard
Consider revising enhancement contract to allow derived identity without use of org.datanucleus.identity.XXXId classes
If we have
@Entity
@IdClass(DependentId.class)
public class Dependent
{
@Id String name;
@Id
@ManyToOne
Employee employee;
}
@Entity
public class Employee
{
@Id
long id;
}
then we ideally want to define DependentId
as
public class DependentId
{
String name; // matches name of @Id attribute
long employee; // matches name of @Id attribute and type of Employee PK
...
}
but currently we require that "employee" is of type org.datanucleus.identity.LongId
dnCopyKeyFieldsToObjectId would need changing to do
Field field = o.getClass().getDeclaredField("name");
field.setAccessible(true);
field.set(o, this.name);
instead of
o.employee = ((LongId)this.employee.dnGetObjectId());
dnCopyKeyFieldsFromObjectId would need changing to do
Object id = new LongId(Employee.class, o.employee);
fc.storeObjectField(0, dnGetExecutionContext().findObject(id, false));
instead of
fc.storeObjectField(0, dnGetExecutionContext().findObject(o.employee, false));
One downside of this possible change is that the current o.employee stored as LongId
also contains the class that is being represented, whereas using just a long loses that