gpt4 book ai didi

java - @OneToOne JPA hibernate 无法确定类型

转载 作者:行者123 更新时间:2023-12-02 11:12:50 24 4
gpt4 key购买 nike

Could not determine type for: com.brainstormers.justlearnit.models.UserDetail, at table: users, for columns: [org.hibernate.mapping.Column(userDetail)]

这是我的用户类:

@Entity
@Table(name = "users")
public class User {
private String username;
private String password;
private int enabled;
@OneToOne(mappedBy = "user", cascade = CascadeType.ALL,
fetch = FetchType.LAZY, optional = false)
private UserDetail userDetail;

public User() {
}

@Id
@Column(name = "username", nullable = false, length = 50)
public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

@Basic
@Column(name = "password", nullable = false, length = 50)
public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

@Basic
@Column(name = "enabled", nullable = false)
public int getEnabled() {
return enabled;
}

public void setEnabled(int enabled) {
this.enabled = enabled;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
User user = (User) o;
return enabled == user.enabled &&
Objects.equals(username, user.username) &&
Objects.equals(password, user.password);
}

@Override
public int hashCode() {

return Objects.hash(username, password, enabled);
}


public UserDetail getUserDetail() {
return userDetail;
}

public void setUserDetail(UserDetail userDetail) {
this.userDetail = userDetail;
}
}

和 UserDetail 类:

@Entity
@Table(name = "user_detail")
public class UserDetail {
private String username;
private String firstName;
private String lastName;
private String email;
private String country;

@OneToOne(fetch = FetchType.LAZY, mappedBy = "userDetail")
@JoinColumn(name = "username")
private User user;


public UserDetail() {
}

@Id
@Column(name = "username", nullable = false, length = 50)
public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

@Basic
@Column(name = "first_name", nullable = false, length = 50)
public String getFirstName() {
return firstName;
}

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

@Basic
@Column(name = "last_name", nullable = false, length = 50)
public String getLastName() {
return lastName;
}

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

@Basic
@Column(name = "email", nullable = false, length = 50)
public String getEmail() {
return email;
}

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

@Basic
@Column(name = "country", nullable = false, length = 50)
public String getCountry() {
return country;
}

public void setCountry(String country) {
this.country = country;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
UserDetail that = (UserDetail) o;
return Objects.equals(username, that.username) &&
Objects.equals(firstName, that.firstName) &&
Objects.equals(lastName, that.lastName) &&
Objects.equals(email, that.email) &&
Objects.equals(country, that.country);
}

@Override
public int hashCode() {

return Objects.hash(username, firstName, lastName, email, country);
}

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}


}

它是由IntelliJ IDEA中的持久化框架生成的。我尝试自己编写实体代码,但得到了相同的结果。

最佳答案

来自 OneToOne#mappedBy 的文档:

(Optional) The field that owns the relationship. This element is only specified on the inverse (non-owning) side of the association.

因此,请删除 UserDetail 中的 mappedBy = "userDetail"

关于java - @OneToOne JPA hibernate 无法确定类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50496327/

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