Наш первый класс бобов Entity.
@Entity
@Table(name = "visamanagmenttable")
@DynamicUpdate
@SelectBeforeUpdate(true)
public class VisaManagementBean {
@Id
@Column(name = "visaManageId")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int visaManageId;
@Column(name = "countryName")
private String countryName;
@Column(name = "visaUniqueId")
private String visaUniqueId;
@Column(name = "visaCategory")
private int visaCategory;
@Column(name = "visaVarientName")
private String visaVarientName;
@Column(name = "visaGovernmentFee")
private String visaGovernmentFee;
@Column(name = "visaServiceFee")
private String visaServiceFee;
@Column(name = "visaSecurityDepositFee")
private String visaSecurityDepositFee;
@Column(name = "visaAdditionalFee")
private String visaAdditionalFee;
@Column(name = "visaAdditionalRemark")
private String visaAdditionalRemark;
@Column(name = "visaSecurityDepositRemark")
private String visaSecurityDepositRemark;
@Column(name = "visaMode")
private String visaMode;
@Column(name = "visaCitizenShipCountry")
private String visaCitizenShipCountry;
@Column(name = "visaLivingCountry")
private String visaLivingCountry;
@Column(name = "visaDescription")
private String visaDescription;
@Column(name = "visaStatus")
private String visaStatus;
@Column(name="createdBy", updatable=false)
private String createdBy;
@Column(name="modifiedBy")
private String modifiedBy;
@CreationTimestamp
@Temporal(TemporalType.TIMESTAMP)
@Column(name="creationDate",updatable=false)
private Date creationDate;
@UpdateTimestamp
@Temporal(TemporalType.TIMESTAMP)
@Column(name="modifiedDate")
private Date modifiedDate;
@Column(name = "status")
private String status;
@Transient
private String[] citizencountry;
@Transient
private String[] livingcountry;
public int getVisaManageId() {
return visaManageId;
}
public String getVisaUniqueId() {
return visaUniqueId;
}
public int getVisaCategory() {
return visaCategory;
}
public String getVisaVarientName() {
return visaVarientName;
}
public String getVisaGovernmentFee() {
return visaGovernmentFee;
}
public String getVisaServiceFee() {
return visaServiceFee;
}
public String getVisaSecurityDepositFee() {
return visaSecurityDepositFee;
}
public String getVisaAdditionalFee() {
return visaAdditionalFee;
}
public String getVisaAdditionalRemark() {
return visaAdditionalRemark;
}
public String getVisaSecurityDepositRemark() {
return visaSecurityDepositRemark;
}
public String getVisaMode() {
return visaMode;
}
public String getVisaCitizenShipCountry() {
return visaCitizenShipCountry;
}
public String getVisaLivingCountry() {
return visaLivingCountry;
}
public String getVisaDescription() {
return visaDescription;
}
public String getVisaStatus() {
return visaStatus;
}
public String getCreatedBy() {
return createdBy;
}
public String getModifiedBy() {
return modifiedBy;
}
public Date getCreationDate() {
return creationDate;
}
public Date getModifiedDate() {
return modifiedDate;
}
public String getStatus() {
return status;
}
public void setVisaManageId(int visaManageId) {
this.visaManageId = visaManageId;
}
public void setVisaUniqueId(String visaUniqueId) {
this.visaUniqueId = visaUniqueId;
}
public void setVisaCategory(int visaCategory) {
this.visaCategory = visaCategory;
}
public void setVisaVarientName(String visaVarientName) {
this.visaVarientName = visaVarientName;
}
public void setVisaGovernmentFee(String visaGovernmentFee) {
this.visaGovernmentFee = visaGovernmentFee;
}
public void setVisaServiceFee(String visaServiceFee) {
this.visaServiceFee = visaServiceFee;
}
public void setVisaSecurityDepositFee(String visaSecurityDepositFee) {
this.visaSecurityDepositFee = visaSecurityDepositFee;
}
public void setVisaAdditionalFee(String visaAdditionalFee) {
this.visaAdditionalFee = visaAdditionalFee;
}
public void setVisaAdditionalRemark(String visaAdditionalRemark) {
this.visaAdditionalRemark = visaAdditionalRemark;
}
public void setVisaSecurityDepositRemark(String visaSecurityDepositRemark) {
this.visaSecurityDepositRemark = visaSecurityDepositRemark;
}
public void setVisaMode(String visaMode) {
this.visaMode = visaMode;
}
public void setVisaCitizenShipCountry(String visaCitizenShipCountry) {
this.visaCitizenShipCountry = visaCitizenShipCountry;
}
public void setVisaLivingCountry(String visaLivingCountry) {
this.visaLivingCountry = visaLivingCountry;
}
public void setVisaDescription(String visaDescription) {
this.visaDescription = visaDescription;
}
public void setVisaStatus(String visaStatus) {
this.visaStatus = visaStatus;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public void setModifiedBy(String modifiedBy) {
this.modifiedBy = modifiedBy;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public void setModifiedDate(Date modifiedDate) {
this.modifiedDate = modifiedDate;
}
public void setStatus(String status) {
this.status = status;
}
public String getCountryName() {
return countryName;
}
public void setCountryName(String countryName) {
this.countryName = countryName;
}
public String[] getCitizencountry() {
return citizencountry;
}
public String[] getLivingcountry() {
return livingcountry;
}
public void setCitizencountry(String[] citizencountry) {
this.citizencountry = citizencountry;
}
public void setLivingcountry(String[] livingcountry) {
this.livingcountry = livingcountry;
}
}
CitizenCountryBean имеет связь между компонентом управления визами (один ко многим)
@Entity
@Table(name = "citizencountrytable")
@DynamicUpdate
@SelectBeforeUpdate(true)
public class CitizenCountryBean {
@Id
@Column(name = "citizenId")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int citizenId;
@Column(name = "citizencountryName")
private String citizencountryName;
@OneToMany(targetEntity = VisaManagementBean.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "citizenId", referencedColumnName = "citizenId")
private Set<VisaManagementBean> visaManagementList = new HashSet<VisaManagementBean>();
@ManyToMany(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
private Set<LivingCountryBean> livingCountryBeanList= new HashSet<>();
@Column(name="createdBy", updatable=false)
private String createdBy;
@Column(name="modifiedBy")
private String modifiedBy;
@CreationTimestamp
@Temporal(TemporalType.TIMESTAMP)
@Column(name="creationDate",updatable=false)
private Date creationDate;
@UpdateTimestamp
@Temporal(TemporalType.TIMESTAMP)
@Column(name="modifiedDate")
private Date modifiedDate;
@Column(name = "status")
private String status;
public int getCitizenId() {
return citizenId;
}
public String getCitizencountryName() {
return citizencountryName;
}
public String getCreatedBy() {
return createdBy;
}
public String getModifiedBy() {
return modifiedBy;
}
public Date getCreationDate() {
return creationDate;
}
public Date getModifiedDate() {
return modifiedDate;
}
public String getStatus() {
return status;
}
public void setCitizenId(int citizenId) {
this.citizenId = citizenId;
}
public void setCitizencountryName(String citizencountryName) {
this.citizencountryName = citizencountryName;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public void setModifiedBy(String modifiedBy) {
this.modifiedBy = modifiedBy;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public void setModifiedDate(Date modifiedDate) {
this.modifiedDate = modifiedDate;
}
public void setStatus(String status) {
this.status = status;
}
public Set<LivingCountryBean> getLivingCountryBeanList() {
return livingCountryBeanList;
}
public Set<VisaManagementBean> getVisaManagementList() {
return visaManagementList;
}
public void setLivingCountryBeanList(Set<LivingCountryBean> livingCountryBeanList) {
this.livingCountryBeanList = livingCountryBeanList;
}
public void setVisaManagementList(Set<VisaManagementBean> visaManagementList) {
this.visaManagementList = visaManagementList;
}
}
наш 3-й бин класса LivingCountryBean и Cityzenshiphip у нас есть отношения многие ко многим. Все наши данные успешно вставлены в соответствующие таблицы, но в нашей 3-й таблице, которая была создана с помощью hibernate из отношения многие ко многим, мы получаем нулевые значения.
@Entity
@Table(name = "livingcountrytable")
@DynamicUpdate
@SelectBeforeUpdate(true)
public class LivingCountryBean {
@Id
@Column(name = "livingId")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int livingId;
@Column(name = "livingcountryName")
private String livingcountryName;
@ManyToMany(mappedBy="livingCountryBeanList")
private Set<CitizenCountryBean> citizenCountryBeanList= new HashSet<>();
@Column(name="createdBy", updatable=false)
private String createdBy;
@Column(name="modifiedBy")
private String modifiedBy;
@CreationTimestamp
@Temporal(TemporalType.TIMESTAMP)
@Column(name="creationDate",updatable=false)
private Date creationDate;
@UpdateTimestamp
@Temporal(TemporalType.TIMESTAMP)
@Column(name="modifiedDate")
private Date modifiedDate;
@Column(name = "status")
private String status;
public int getLivingId() {
return livingId;
}
public String getLivingcountryName() {
return livingcountryName;
}
public Set<CitizenCountryBean> getCitizenCountryBeanList() {
return citizenCountryBeanList;
}
public void setCitizenCountryBeanList(Set<CitizenCountryBean> citizenCountryBeanList) {
this.citizenCountryBeanList = citizenCountryBeanList;
}
public String getCreatedBy() {
return createdBy;
}
public String getModifiedBy() {
return modifiedBy;
}
public Date getCreationDate() {
return creationDate;
}
public Date getModifiedDate() {
return modifiedDate;
}
public String getStatus() {
return status;
}
public void setLivingId(int livingId) {
this.livingId = livingId;
}
public void setLivingcountryName(String livingcountryName) {
this.livingcountryName = livingcountryName;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public void setModifiedBy(String modifiedBy) {
this.modifiedBy = modifiedBy;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public void setModifiedDate(Date modifiedDate) {
this.modifiedDate = modifiedDate;
}
public void setStatus(String status) {
this.status = status;
}
}
Наш код DAO в Spring ORM использует шаблонный класс hibernate.
@Override
public int createVisaManagement(CitizenCountryBean citizenCountryBean) {
Integer id = (Integer) hibernateTemplate.save(citizenCountryBean);
return id;
}