Symptom:
IllegalAccessError occured : tried to access method models.User.(Ljava/lang/String;)V from class models.User$Factory
Cause:
* PlayMorphia code enhancement changed the access level of the constructor some how.
Background:
I have a parent model class:
@Entity public class FBUser extends Model {
...
public static connect() {
...
return fact.create();
}
public static interface UserFactory {
FBUser create(String userId);
}
@Inject
public static UserFactory fact;
}
And then I created a sub class
@Entity public class User extends FBUser {
protected User(String id) {...}
public static class Factory implements IUserFactory {
@Override
public FBUser create(String id) {
return new User(id);
}
}
}
The problem happens at line 6:
return new User(id)
, it's a bit strange that although Factory is an another class, it's embedded inside User class and should have the access to the protected
User(String)
constructor. There is also not complaints from the compiler. Actually if I suppress the @Entity annotation from the User class (which actually suppress the code enhancement from PlayMorphia module) the error will not occur.
So it looks to me that the code enhancement somehow break the embedded class accessible state. The solution is simple: make the protected constructor public.
Reference:
* http://www.playframework.org
* http://www.playframework.org/modules/morphia