我正在使用Hibernate for ORM开发一个Sping Boot 应用程序,我面临着实体Map的问题。当我尝试运行我的应用程序时,它抛出以下异常:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Column 'id' is duplicated in mapping for entity 'com.intelligentadmindashboard.intelligentadmindashboard.domain.Agency' (use '@Column(insertable=false, updatable=false)' when mapping multiple properties to the same column)
Caused by: org.hibernate.MappingException: Column 'id' is duplicated in mapping for entity 'com.intelligentadmindashboard.intelligentadmindashboard.domain.Agency' (use '@Column(insertable=false, updatable=false)' when mapping multiple properties to the same column)
Caused by: jakarta.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Column 'id' is duplicated in mapping for entity 'com.intelligentadmindashboard.intelligentadmindashboard.domain.Agency' (use '@Column(insertable=false, updatable=false)' when mapping multiple properties to the same column)
字符串
这个问题似乎与机构实体有关,机构实体的定义如下:
@Entity
@Table(name="tr_agency")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Agency {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id", insertable = false, updatable = false)
private long id;
@Column(name="label")
private String label;
@Column(name="leave_balance")
private Double leave_balance;
private LocalDateTime deleted_at;
private String code;
@Column(name="has_previous_year_holidays")
private Boolean has_previous_year_holidays;
@Embedded
private Country country;
}
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table(name="collaborator")
public class Collaborator {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
//other fields
@ManyToOne(targetEntity = Agency.class)
@JoinColumn(name="agency_id",referencedColumnName = "id",insertable = false,updatable = false)
private Agency agency;
@ManyToOne(targetEntity = ServiceType.class)
@JoinColumn(name="service_id",referencedColumnName = "id")
private ServiceType serviceType;
@ManyToOne(targetEntity = Departement.class)
@JoinColumn(name="departement_id",referencedColumnName = "id")
private Departement departement;
@ManyToOne(targetEntity = StatutProfessional.class)
@JoinColumn(name="statut_professionnel_id",referencedColumnName = "id")
private StatutProfessional statutProfessional;
}
的数据
我不知道问题到底出在哪里
1条答案
按热度按时间lx0bsm1f1#
在您的代理实体中注解此行
字符串