我想插入包含从同一表(组织表)引用的两个文件名organization_id和account_id的行。
EntityModel.java
@ManyToOne
@JoinColumn(name = "organization_id")
private OrganizationModel organization;
@ManyToOne
@JoinColumn(name = "account_id")
private OrganizationModel account;
OrganizationModel.java
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "organization_id", unique = true, nullable = false)
private int organizationId;
@OneToMany(mappedBy = "organization")
private Set<EntityModel> organization;
但我得到以下错误。
Repeated column in mapping for entity: com.party.OrganizationModel column: organization_id (should be mapped with insert="false" update="false")
当我添加insert="false"
update="false"
帐户时,错误消失了。但是我需要同时插入帐户和组织。
为EntityModel添加一个主键。
这是对我有用的代码:
@Entity
@Table(name = "EntityModel")
public class EntityModel {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "entity_model_id", unique = true, nullable = false)
private int entityModelId;
@ManyToOne
@JoinColumn(name = "organization_id")
private OrganizationModel organization;
@ManyToOne
@JoinColumn(name = "account_id")
private OrganizationModel account;
}
@Entity
@Table(name = "OrganizationModel")
public class OrganizationModel {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "organization_id", unique = true, nullable = false)
private int organizationId;
@OneToMany(mappedBy = "organization")
private Set<EntityModel> organization;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句