Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider revising enhancement contract to allow derived identity without use of org.datanucleus.identity.XXXId classes #155

Open
andyjefferson opened this issue Nov 20, 2016 · 0 comments

Comments

@andyjefferson
Copy link
Member

andyjefferson commented Nov 20, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant