我有一个 PostgreSQL 表和一个表示该表的数据类。我使用注解进行映射,而不是映射 xml 文件。我删除了一些列,因为 db 表和映射类都不需要它们。但我得到一个运行时休眠异常:已删除列上缺少列。这些列在其他任何地方都没有引用,否则编译会失败。现在我将列添加回表(但不是类),它工作正常。有人可以指出方向吗?如果你愿意,我可以发布代码,但 t 只是一个简单的数据类和一个表。
例外:
ERROR: org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'phaseRepository' defined in Servle
tContext resource [/WEB-INF/context/spring-entity.xml]: Cannot resolve reference to bean 'sessionFactory' while setting be
an property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/context/spring-entity.xml]: Invocation of init method failed; nested exception is
org.hibernate.HibernateException: Missing column: patient_given_name in public.patient_detail at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResol
ver.java:328) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionVal
ueResolver.java:106)
实体类:
@Entity
@Table(name = "patient_detail")
public class PatientDetail implements Serializable {
private static final long serialVersionUID = -7765251798211029654L;
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "patient_detail_id_seq")
@SequenceGenerator(name = " patient_detail_id_seq ", sequenceName = " patient_detail_id_seq ", allocationSize = 1)
private long id;
@Column(name = " templateId ")
private long templateId;
@Column(name = "description")
private String description;
@Column(name = "anatomical_name")
private String anatomicalName;
@Column(name = "additional_comments")
private String additionalComments;
@Column(name = "create_date")
private Date createDate;
@Column(name = "modified_date")
private Date modifiedDate;
@ManyToOne
@ForeignKey(name = "fk_patient_id")
@JoinColumn(name = "patient_id")
private Patient patient;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@Fetch(FetchMode.SELECT)
@JoinColumn(name = "patient_id")
private List<PatientPhase> phases;
.....
getters and setters