Under Hibernate Core 3.1 + Hibernate Annotations 3.1beta7
Code:
package zappy.htlgm.ejb1;
import javax.persistence.AccessType;
import javax.persistence.AttributeOverride;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
@Entity(access=AccessType.FIELD)
@NamedQuery(name="user.valid", queryString="select u from User u where u.id=:id")
@NamedQuery(name="user.invalid", queryString="select u from User u where id=:id")
public class User {
@Id
@Column(name="USR000")
private int id;
@Column(name = "USR001")
private String mName;
public int getId() {
return id;
}
public void setId(int pId) {
id = pId;
}
public String getName() {
return mName;
}
private void setName(String pName) {
mName = pName;
}
}
Problems:
1. @NamedQuery stands for EJB3 QL, why query user.valid "where u.id=:id"(where "u.id" prefixed with "u.") would be passed, but query user.invalid "where id=:id"(without "u." prefix) not? (got java.sql.SQLException: Unknown column 'id' in 'where clause')
2. change query.invalid slightly to be "where USER000 = :id", then it passed, why? but USER000 is a column name but not a field one...
3. JSR-200 final draft describe that @NameQuery has two attribute: name and query, but why Hibernate Annotations implements it as queryString?
4. following consitent coding style(POJO is better to be transient), so how can I preserve the "mName"(prefixed with 'm'), but used as 'name' in query language, but mapping to 'USR001' in physical table?