gpt4 book ai didi

java - Hibernate 无法解析属性

转载 作者:行者123 更新时间:2023-12-01 10:14:28 28 4
gpt4 key购买 nike

Hibernate 无法解析我的属性,我不明白这是为什么。尝试查看其他 stackoverflow 问题,但我无法解决它。

这是我的两个类。

用户:

@Entity
@Table(name = "users")
public class User {

@Id
@Column(name = "user_id")
@JsonIgnore
private int userId;

@ManyToOne
@JoinColumn(name = "ad_object_id")
private ADUser activeDirectoryUser;

@Column(name = "created_at")
private DateTime createdAt;

@Column(name = "updated_at")
private DateTime updatedAt;

public User() {}

public User(int userId, ADUser activeDirectoryUser, DateTime createdAt, DateTime updatedAt) {
this.userId = userId;
this.activeDirectoryUser = activeDirectoryUser;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
}

public int getUserId() {
return userId;
}

public void setUserId(int userId) {
this.userId = userId;
}

public ADUser getActiveDirectoryUser() {
return activeDirectoryUser;
}

public void setActiveDirectoryUser(ADUser activeDirectoryUser) {
this.activeDirectoryUser = activeDirectoryUser;
}

public DateTime getCreatedAt() {
return createdAt;
}

public void setCreatedAt(DateTime createdAt) {
this.createdAt = createdAt;
}

public DateTime getUpdatedAt() {
return updatedAt;
}

public void setUpdatedAt(DateTime updatedAt) {
this.updatedAt = updatedAt;
}
}

AD 用户:

@Entity
@Table(name = "ad_users")
public class ADUser {

@Id
@Column(name = "ad_object_id")
@JsonIgnore
private String activeDirectoryId;

@Column(name = "email")
private String email;

@Column(name = "full_name")
private String fullName;

@Column(name = "first_name")
private String firstName;

@Column(name = "last_name")
private String lastName;

@ManyToOne
@JoinColumn(name = "ad_group_id")
private ADGroup classInfo;

public ADUser() {}

public ADUser(String activeDirectoryId, String email, String fullName, String firstName, String lastName, ADGroup classInfo) {
this.activeDirectoryId = activeDirectoryId;
this.email = email;
this.fullName = fullName;
this.firstName = firstName;
this.lastName = lastName;
this.classInfo = classInfo;
}

public String getActiveDirectoryId() {
return activeDirectoryId;
}

public void setActiveDirectoryId(String activeDirectoryId) {
this.activeDirectoryId = activeDirectoryId;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getFullName() {
return fullName;
}

public void setFullName(String fullName) {
this.fullName = fullName;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public ADGroup getClassInfo() {
return classInfo;
}

public void setClassInfo(ADGroup classInfo) {
this.classInfo = classInfo;
}
}

我正在尝试使用以下方法查找用户。

public Optional<User> findByEmail(String email){
Criteria criteria = criteria().add(Restrictions.eq("activeDirectoryUser.email", email));

return Optional.fromNullable(uniqueResult(criteria));
}

这是我收到的错误。

org.hibernate.QueryException: could not resolve property: activeDirectoryUser.email of: -removed-.objects.User

最佳答案

您需要为关联使用别名

Criteria criteria = criteria().createAlias("activeDirectoryUser",
"activeDirectoryUser").add(Restrictions.eq("activeDirectoryUser.email", email));

关于java - Hibernate 无法解析属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35986160/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com