Мне нужно установить связь один-ко-многим между Обществом и Таблицей Блоков. Ошибка: Invocation of init method failed; nested exception is org.hibernate.MappingException: Repeated column in mapping for entity: com.example.domain.SocietyBlockFloor column: society_id (should be mapped with insert="false" update="false")
SocietyDetails. java
package com.example.domain;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
@Entity
@Table(name="society_details")
public class SocietyDetails {
public static final long serialVersionUID = 1L;
@Id
@Column(name = "society_id")
private String societyId;
@Column(name = "society_name")
private String societyName;
@Column (name = "society_address")
private String societyAddress;
@Column (name = "society_country_details_code")
private String societyCountryDetailsCode;
@OneToMany(mappedBy = "societyDetails", cascade = CascadeType.ALL)
private List<SocietyBlockFloor> societyBlockFloor = new ArrayList<SocietyBlockFloor>();
@Override
public String toString() {
return "Society{" +
"societyId='" + societyId + '\'' +
", societyName='" + societyName + '\'' +
", societyAddress='" + societyAddress + '\'' +
", societyCountryDetailsCode='" + societyCountryDetailsCode + '\'' +
", societyBlockFloor='" + societyBlockFloor + '\'' +
'}';
}
public static long getSerialVersionUID() {
return serialVersionUID;
}
public String getSocietyId() {
return societyId;
}
public void setSocietyId(String societyId) {
this.societyId = societyId;
}
public String getSocietyName() {
return societyName;
}
public void setSocietyName(String societyName) {
this.societyName = societyName;
}
public String getSocietyAddress() {
return societyAddress;
}
public void setSocietyAddress(String societyAddress) {
this.societyAddress = societyAddress;
}
public String getSocietyCountryDetailsCode() {
return societyCountryDetailsCode;
}
public void setSocietyCountryDetailsCode(String societyCountryDetailsCode) {
this.societyCountryDetailsCode = societyCountryDetailsCode;
}
public List<SocietyBlockFloor> getSocietyBlockFloor() {
return societyBlockFloor;
}
public void setSocietyBlockFloor(List<SocietyBlockFloor> societyBlockFloor) {
this.societyBlockFloor = societyBlockFloor;
}
}
SocietyBlockFloor. java
package com.example.domain;
import javax.persistence.*;
import java.io.Serializable;
@Entity
@Table(name="society_block_floor")
public class SocietyBlockFloor implements Serializable {
public static final long serialVersionUID = 1L;
@Id
@Column(name="society_id")
private String societyBlockFloorId;
@Column(name="society_block")
private String societyBlock;
@Column(name="society_floor")
private String societyFloor;
@ManyToOne
@JoinColumn(name = "society_id", nullable = false)
private SocietyDetails societyDetails;
@Override
public String toString() {
return "HASocietyBlockFloor{" +
"societyBlockFloorId='" + societyBlockFloorId + '\'' +
", societyBlock='" + societyBlock + '\'' +
", societyFloor='" + societyFloor + '\'' +
", societyDetails='" + societyDetails + '\'' +
'}';
}
public String getSocietyBlockFloorId() {
return societyBlockFloorId;
}
public String getSocietyBlock() {
return societyBlock;
}
public void setSocietyBlock(String societyBlock) {
this.societyBlock = societyBlock;
}
public String getSocietyFloor() {
return societyFloor;
}
public void setSocietyFloor(String societyFloor) {
this.societyFloor = societyFloor;
}
public SocietyDetails getSocietyDetails() {
return societyDetails;
}
public void setSocietyDetails(SocietyDetails societyDetails) {
this.societyDetails = societyDetails;
}
}
DAO Class
package com.example.dao.impl;
@Repository
public class SocietyDetailsDAOImpl extends BaseDAOImpl implements SocietyDetailsDAO {
@Override
public List<SocietyDetails> getSocietyDetailsByName(String societyName) throws Exception {
try {
String queryString = "from SocietyDetails society JOIN society.societyBlockFloor where society.societyName=:societyName";
Query query = getSessionFactory().getCurrentSession().createQuery(queryString);
query.setParameter("societyName", societyName);
List<SocietyDetails> societyDetails = query.list();
return societyDetails;
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
Я уже пытался изменить имя SocietyBlockFloor.societyBlockFloorId, но затем в предложении ON он все еще использует (society.societyId = societyBlockFloor.societyId) где SocietyBlockFloor.societyId не существует.