Здесь у меня есть два класса JPA: TimeSheet и TimeSheetDetails
В этом случае у меня возникают проблемы с обновлением расписания, в то время как обновление расписания (основной таблицы) обновляется плавно, но детали расписания (дочерняя таблица) генерируютсяновые строки вместо обновления, а таблица ссылок также обновлена новыми значениями .....
Вот что такое re
1) TimeSheet.java
@Entity
@Table(name = AMAM_Constants.tb_name.TIMESHEET, schema = AMAM_Constants.db_name)
public class TimeSheet implements Serializable {
private long ts_Id;
private String ts_Candidate;
private Date ts_Sdate;
private Date ts_Edate;
private String active;
private String ts_Type;
private String ts_Status;
private List<TimeSheetDetails> timesheetDetails = new ArrayList<TimeSheetDetails>();
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinTable(name = AMAM_Constants.tb_name.TIMESHEET_LINK_DETAILS, joinColumns = {
@JoinColumn(name = "TS_ID")}, inverseJoinColumns = {
@JoinColumn(name = "TSD_ID")
})
public List<TimeSheetDetails> getTimesheetDetails() {
return timesheetDetails;
}
public void setTimesheetDetails(List<TimeSheetDetails> timesheetDetails) {
this.timesheetDetails = timesheetDetails;
}
@Column(name = "ACTIVE", length = 1)
public String getActive() {
return active;
}
public void setActive(String active) {
this.active = active;
}
@Column(name = "TS_CANDIDATE", length = 25)
public String getTs_Candidate() {
return ts_Candidate;
}
public void setTs_Candidate(String ts_Candidate) {
this.ts_Candidate = ts_Candidate;
}
@Column(name = "TS_EDATE")
public Date getTs_Edate() {
return ts_Edate;
}
public void setTs_Edate(Date ts_Edate) {
this.ts_Edate = ts_Edate;
}
@Id
@GeneratedValue
@Column(name = "TS_ID")
public long getTs_Id() {
return ts_Id;
}
public void setTs_Id(long ts_Id) {
this.ts_Id = ts_Id;
}
@Column(name = "TS_SDATE")
public Date getTs_Sdate() {
return ts_Sdate;
}
public void setTs_Sdate(Date ts_Sdate) {
this.ts_Sdate = ts_Sdate;
}
@Column(name = "TS_STATUS", length = 25)
public String getTs_Status() {
return ts_Status;
}
public void setTs_Status(String ts_Status) {
this.ts_Status = ts_Status;
}
@Column(name = "TS_TYPE", length = 10)
public String getTs_Type() {
return ts_Type;
}
public void setTs_Type(String ts_Type) {
this.ts_Type = ts_Type;
}
}
@Entity
@Table(name = AMAM_Constants.tb_name.TIMESHEET_DETAILS, schema = AMAM_Constants.db_name)
public class TimeSheetDetails implements Serializable {
private long tsd_Id;
private String tsd_Po;
private Date tsd_Date;
private String tsd_DayName;
private int tsd_Hours;
private String tsd_HourType;
private String tsd_DayType;
@Column(name = "TSD_DATE")
public Date getTsd_Date() {
return tsd_Date;
}
public void setTsd_Date(Date tsd_Date) {
this.tsd_Date = tsd_Date;
}
@Column(name = "TSD_DAYNAME", length = 25)
public String getTsd_DayName() {
return tsd_DayName;
}
public void setTsd_DayName(String tsd_DayName) {
this.tsd_DayName = tsd_DayName;
}
@Column(name = "TSD_DAYTYPE", length = 25)
public String getTsd_DayType() {
return tsd_DayType;
}
public void setTsd_DayType(String tsd_DayType) {
this.tsd_DayType = tsd_DayType;
}
@Column(name = "TSD_HOURTYPE", length = 25)
public String getTsd_HourType() {
return tsd_HourType;
}
public void setTsd_HourType(String tsd_HourType) {
this.tsd_HourType = tsd_HourType;
}
@Column(name = "TSD_HOURS")
public int getTsd_Hours() {
return tsd_Hours;
}
public void setTsd_Hours(int tsd_Hours) {
this.tsd_Hours = tsd_Hours;
}
@Id
@GeneratedValue
@Column(name = "TSD_ID")
public long getTsd_Id() {
return tsd_Id;
}
public void setTsd_Id(long tsd_Id) {
this.tsd_Id = tsd_Id;
}
@Column(name = "TSD_PO", length = 25)
public String getTsd_Po() {
return tsd_Po;
}
public void setTsd_Po(String tsd_Po) {
this.tsd_Po = tsd_Po;
}
}
public class TimeSheetDao extends HibDao {
public void insertTimeSheet(TimeSheet objTimeSheet) throws Exception {
try {
begin();
getSession().save(objTimeSheet);
commit();
} catch (Exception ex) {
rollback();
throw new Exception(ex.getMessage());
} finally {
flush();
close();
}
}
public void updateTimeSheet(TimeSheet objTimeSheet) throws Exception {
try {
begin();
TimeSheet obj =(TimeSheet)getSession().get(TimeSheet.class,objTimeSheet.getTs_Id());
obj.setActive("Y");
obj.setTimesheetDetails(objTimeSheet.getTimesheetDetails());
obj.setTs_Candidate(objTimeSheet.getTs_Candidate());
obj.setTs_Edate(objTimeSheet.getTs_Edate());
obj.setTs_Sdate(objTimeSheet.getTs_Sdate());
obj.setTs_Status(objTimeSheet.getTs_Status());
obj.setTs_Type(objTimeSheet.getTs_Type());
getSession().update(obj);
commit();
} catch (Exception ex) {
rollback();
throw new Exception(ex.getMessage());
} finally {
flush();
close();
}
}
}