org.postgresql.util.PSQLException: ERROR: column user0_.id 不存在 - Hibernate
2022-09-01 02:30:10
我有一个模型类,它使用休眠映射到postgres数据库。我的模型类是:
@Entity
@Table(name="USER")
public class User {
@Id
@GeneratedValue
@Column(name="id")
private long id;
@Column(name="username", unique=true)
private String username;
@Column(name="email")
private String email;
@Column(name="created")
private Timestamp created;
public User(long id, String username, String email) {
this.id = id;
this.username = username;
this.email = email;
}
}
我尝试使用以下查询检索用户名为“adam”的用户:
tx = session.beginTransaction();
TypedQuery<User> query = session.createQuery("FROM User u WHERE u.username = :username", User.class).setParameter("username", "adam");
user = query.getSingleResult();
我得到一个例外,上面写着:
org.postgresql.util.PSQLException: ERROR: column user0_.id does not exist
我的数据库来自 bash shell 看起来像这样:
休眠如何将类属性映射到表列?它是基于唯一匹配,还是也尝试基于数据类型和约束(如唯一/自动增量)进行匹配?@Column(name="username")