我正在使用hibernate进行映射和类,但我得到了错误。我的映射是一个学生有很多学校科目。我首先使用postgres制作数据库。谢谢!
CREATE TABLE aluno
(
idAluno serial,
datanascimento date,
matricula character varying(255),
nome character varying(255),
CONSTRAINT pkAluno PRIMARY KEY (idAluno)
);
CREATE TABLE materiaaluno
(
idCurso serial,
nome character varying(255),
idAluno integer NOT NULL,
CONSTRAINT pkMateriAluno PRIMARY KEY (idcurso),
CONSTRAINT fkAluno FOREIGN KEY(idAluno) REFERENCES aluno(idAluno)
);
警告:#{alunoBean.salvar()}:java.lang.Exception:无法通过modelo.Materia.idcurso的反射getter获取字段值 javax.faces.FacesException:#{alunoBean.salvar()}:java.lang.Exception:无法通过modelo.Materia.idcurso的反射getter获取字段值
阿鲁诺班
package modelo;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@Entity
@Table(name = "aluno")
public class Aluno implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "idaluno")
private Integer idaluno;
@Column(name = "nome")
private String nome;
@Temporal(TemporalType.DATE)
@Column(name = "datanascimento")
private Date datanascimento;
@Column(name = "matricula")
private String matricula;
@OneToMany(mappedBy = "aluno", cascade = CascadeType.ALL)
private List<Materia> materias;
// contructors, getters and setters
}
Materia class
package modelo;
import java.io.Serializable;
import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "materiaaluno")
public class Materia implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "idcurso")
private Integer idcurso;
@Column(name = "nome")
private String nome;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "idaluno")
private Aluno aluno;
// constructor, getters and setters
}
答案 0 :(得分:0)
你可能忘记/误写了实体b
中的二传手和吸气者
Hibernate尝试通过反射来访问字段,否则就不会这样做。
检查字段Materia