gpt4 book ai didi

java - Hibernate 持久实体应该有一个主键

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

我有以下实体。我正在尝试更换后翼。 (见图)但我收到以下错误:持久实体应该有一个主键。

(我是 hibernate 的新手)(如果您还需要 UserEntity 类,请发表评论)(提前致谢!)

enter image description here

@Entity
@Table(name = "Student", schema = "pad_ijburg", catalog = "")
public class StudentEntity extends UserEntity {
private Integer idGroup;
private int idUser;

@Basic
@Column(name = "idGroup")
public Integer getIdGroup() {
return idGroup;
}

public void setIdGroup(Integer idGroup) {
this.idGroup = idGroup;
}

@Basic
@Column
public int getIdUser() {
return idUser;
}

public void setIdUser(int idUser) {
this.idUser = idUser;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

StudentEntity that = (StudentEntity) o;

if (idUser != that.idUser) return false;
if (idGroup != null ? !idGroup.equals(that.idGroup) : that.idGroup != null) return false;

return true;
}

@Override
public int hashCode() {
int result = idGroup != null ? idGroup.hashCode() : 0;
result = 31 * result + idUser;
return result;
}
}

package org.hva.folivora.model.user;

import javax.persistence.*;

/**
*
*/
@Entity
@Table(name = "User", schema = "pad_ijburg")
@Inheritance(strategy = InheritanceType.JOINED)
public class UserEntity {
private int idUser;
private String email;
private String firstName;
private String lastName;
private String password;
private Boolean admin;

@Id @GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "idUser", nullable = false)
public int getIdUser() {
return idUser;
}

public void setIdUser(int idUser) {
this.idUser = idUser;
}

@Basic
@Column(name = "email")
public String getEmail() {
return email;
}

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

@Basic
@Column(name = "firstName")
public String getFirstName() {
return firstName;
}

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

@Basic
@Column(name = "lastName")
public String getLastName() {
return lastName;
}

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

@Basic
@Column(name = "password")
public String getPassword() {
return password;
}

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

@Basic
@Column(name = "admin")
public Boolean getAdmin() {
return admin;
}

public void setAdmin(Boolean admin) {
this.admin = admin;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

UserEntity that = (UserEntity) o;

if (idUser != that.idUser) return false;
if (email != null ? !email.equals(that.email) : that.email != null) return false;
if (firstName != null ? !firstName.equals(that.firstName) : that.firstName != null) return false;
if (lastName != null ? !lastName.equals(that.lastName) : that.lastName != null) return false;
if (password != null ? !password.equals(that.password) : that.password != null) return false;
if (admin != null ? !admin.equals(that.admin) : that.admin != null) return false;

return true;
}

@Override
public int hashCode() {
int result = idUser;
result = 31 * result + (email != null ? email.hashCode() : 0);
result = 31 * result + (firstName != null ? firstName.hashCode() : 0);
result = 31 * result + (lastName != null ? lastName.hashCode() : 0);
result = 31 * result + (password != null ? password.hashCode() : 0);
result = 31 * result + (admin != null ? admin.hashCode() : 0);
return result;
}
}

编辑:使用生成的值标识时也会出现以下错误

.StudentEntity column: idUser (should be mapped with insert="false" update="false")

最佳答案

能否请您尝试替换您的代码

@GeneratedValue(strategy=GenerationType.AUTO)

@GeneratedValue(strategy=GenerationType.IDENTITY)

关于java - Hibernate 持久实体应该有一个主键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36754568/

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