In my project I'm using JPA2 and Hibernate within eclipse Indigo.
I have an abstract BaseEntity class which provides some fields that are needed for all entities in my project. Therefore this class is extended by all other entities I use in my project.
One of the fields in BaseEntity is a boolean field deleted
, which is needed to mark an entry as deleted (it's not allowed to physically delete an object from the database).
Now when I try to set up a named query in a subclass and use a "NOT u.deleted" in the WHERE-clause, i get the following error message from the compiler:
The state field path 'r.deleted' cannot be resolved to a valid type.
Below the code of the BaseEntity:
@MappedSuperclass
public abstract class BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected Long id;
@Version
protected int version;
@Column(nullable = false, columnDefinition = "boolean default false")
protected boolean deleted;
public boolean isDeleted() {
return deleted;
}
public boolean getDeleted() { // for test-purposes introduced both - isDeleted() & getDeleted()
return deleted;
}
public void setDeleted(boolean deleted) {
this.deleted = deleted;
}
// some other attributes, getters & setters
}
The code of an inheriting class:
@Entity
@Table(name = "User")
@NamedQueries({
@NamedQuery(name = "getAllUsers", query = "SELECT u FROM User u WHERE NOT u.deleted")
})
public class User extends BaseEntity {
// some other fields and getter/setters
}
Any guesses what could be wrong?
EDIT: updated code according to comments below.