I have 2 tables: Accounts and AccountDetailsData. I mapped there are to 2 classes:
@Entity
@Table(name = "Accounts", schema = "dbo", catalog = "core")
public class AccountsEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Basic
@Column(name = "status")
private String status;
@Basic
@Column(name = "enabled")
private Boolean enabled;
@Basic
@Column(name = "timestamp")
private Timestamp timestamp;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy="accountsEntityObject")
private List<AccountsDetailDataEntity> detailDataEntity;
public AccountsEntity() {
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Boolean getEnabled() {
return enabled;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
public Timestamp getTimestamp() {
return timestamp;
}
public void setTimestamp(Timestamp timestamp) {
this.timestamp = timestamp;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AccountsEntity that = (AccountsEntity) o;
if (enabled != null ? !enabled.equals(that.enabled) : that.enabled != null) return false;
if (id != null ? !id.equals(that.id) : that.id != null) return false;
if (status != null ? !status.equals(that.status) : that.status != null) return false;
if (timestamp != null ? !timestamp.equals(that.timestamp) : that.timestamp != null) return false;
return true;
}
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (status != null ? status.hashCode() : 0);
result = 31 * result + (enabled != null ? enabled.hashCode() : 0);
result = 31 * result + (timestamp != null ? timestamp.hashCode() : 0);
return result;
}
}
And
@Entity
@Table(name = "AccountsDetailData", schema = "dbo", catalog = "core")
public class AccountsDetailDataEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Basic
@Column(name = "additionalValue")
private String additionalValue;
@Basic
@Column(name = "status")
private String status;
@Basic
@Column(name = "enabled")
private Boolean enabled;
@ManyToOne(cascade = {CascadeType.REFRESH}, fetch = FetchType.LAZY)
@JoinColumn(name = "id")
private AccountsEntity accountsEntityObject;
public AccountsDetailDataEntity() {
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getAdditionalValue() {
return additionalValue;
}
public void setAdditionalValue(String additionalValue) {
this.additionalValue = additionalValue;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Boolean getEnabled() {
return enabled;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AccountsDetailDataEntity that = (AccountsDetailDataEntity) o;
if (additionalValue != null ? !additionalValue.equals(that.additionalValue) : that.additionalValue != null)
return false;
if (enabled != null ? !enabled.equals(that.enabled) : that.enabled != null) return false;
if (id != null ? !id.equals(that.id) : that.id != null) return false;
if (status != null ? !status.equals(that.status) : that.status != null) return false;
return true;
}
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (additionalValue != null ? additionalValue.hashCode() : 0);
result = 31 * result + (status != null ? status.hashCode() : 0);
result = 31 * result + (enabled != null ? enabled.hashCode() : 0);
return result;
}
}
When I run this code:
Session session = getCoreObject().getDataBase().getCoreSession();
AccountsEntity fieldsEntity = (AccountsEntity) session.load(AccountsEntity.class,1);
I have exception:
org.hibernate.MappingException: Repeated column in mapping for entity: com.company.hrplus.core.rest.Account.enteties.AccountsDetailDataEntity column: id (should be mapped with insert="false" update="false")
I can't understant where is the problem. Please help.