作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我按下“完成”按钮时,我创建了“从实体类新建 JPA Controller 类”,然后收到以下错误。
Users.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.mycompany.mavenproject1.exceptions.exceptions.exceptions;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* @author OZGUR-PC
*/
@Entity
@Table(name = "users")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Users.findAll", query = "SELECT u FROM Users u"),
@NamedQuery(name = "Users.findById", query = "SELECT u FROM Users u WHERE u.id = :id"),
@NamedQuery(name = "Users.findByUserName", query = "SELECT u FROM Users u WHERE u.userName = :userName")})
public class Users implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 50)
@Column(name = "user_name")
private String userName;
public Users() {
}
public Users(Integer id) {
this.id = id;
}
public Users(Integer id, String userName) {
this.id = id;
this.userName = userName;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Users)) {
return false;
}
Users other = (Users) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "com.mycompany.mavenproject1.exceptions.exceptions.exceptions.Users[ id=" + id + " ]";
}
}
我需要关于如何解决这个问题的想法。预先感谢您的帮助。
最佳答案
确保您已为您的实体声明了标识符。例如,假设有一个名为 Student
的实体,其标识符为 studentId
和属性 name
那么该实体应该是这样的,它应该有 setter以及字段的 getter 方法:
@Entity
public class Student {
@Id
@GeneratedValue
private int studentId;
private String name;
public String getName() {
return name;
}
public int getStudentId() {
return studentId;
}
public void setStudentId(int studentId) {
this.studentId = studentId;
}
public void setName(String name) {
this.name = name;
}
}
关于mysql - 如何修复 "Coult not find Id property. Be sure the accessor method name matches the veriable name"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27043511/
当我按下“完成”按钮时,我创建了“从实体类新建 JPA Controller 类”,然后收到以下错误。 Users.java /* * To change this license header, c
我是一名优秀的程序员,十分优秀!