I have a base class:
public abstract class HotObject extends BaseObject { private Integer activity; protected HotObject() { activity = 1; } public Integer getActivity() { return activity; } public void setActivity(Integer activity) { this.activity = activity; } public void increaseActivity() { activity += 1; } protected abstract Integer getDecrease(); public Boolean decreaseActivity() { Integer adaptedDecrease; if (activity < 50) { adaptedDecrease = getDecrease(); } else if (activity < 100) { adaptedDecrease = getDecrease() + 5; } else { adaptedDecrease = getDecrease() + 10; } activity = activity - ((activity * adaptedDecrease) / 100) - 1; return activity < 2; } }
And I have an inherited class:
@Entity public class HotTag extends HotObject implements Serializable { private static final Integer decrease = 20; // percent // @Id private String name; public HotTag() { } public HotTag(String name) { this.name = name; } public String getName() { return name; } @Override protected Integer getDecrease() { return decrease; } }
Now, when issuing the following query:
TypedQuery<HotTag> query = em.createQuery("SELECT t FROM HotTag t ORDER BY t.activity DESC", HotTag.class);
I get the exception (in objectdb 2.4.1):
com.objectdb.o.UserException: Field 'activity' is not found in type 'net.pocketservices.athene.objects.persistent.HotTag'
This can only be resolved by changing
private Integer activity;
to
public Integer activity;
in the super class. This looks like a bug to me. Normally, private access is not an issue with objectdb. I do queries on private fields all the time... So, when querying a private inherited field, I would expect this to work as well. Or is this according to the JPA spec? Then forgive me asking a stupid question.. :)
Thanks for insight!
Best, Benjamin