Never mind.. I removed the parent field from the child declaration and it worked........
Two tables ( one-to-many)
=====================
1) s_holiday
id_s_holiday KEY
other columns ..
2) s_holiday_apply2
id_s_holiday_apply2 KEY
id_s_holiday Foreign Key from s_holiday
other columns...
With the mapping below, the MERGE statment doesnot auto-populate the foreign key ( id_s_holiday)
Code:
in table s_holiday_apply2...
[1/24/09 18:10:33:468 CST] 0000002f SystemOut O Into getNestedThrowable ... org.springframework.dao.DataIntegrityViolationException: Could not execute JDBC batch update; nested exception is org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
[1/24/09 18:10:33:468 CST] 0000002f SystemOut O Into getNestedThrowable ... org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
[1/24/09 18:10:33:468 CST] 0000002f SystemOut O Into getNestedThrowable ... java.sql.BatchUpdateException: ORA-01400: cannot insert NULL into ("HHSC_COMM_IT"."S_HOLIDAY_APPLY2"."ID_S_HOLIDAY")
What is missing?
Any help will be greatly appreciated.
Thanks
Prasad
Code:
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.Version;
import org.hibernate.annotations.MapKey;
@Entity
@Table(name="S_HOLIDAY")
@javax.persistence.SequenceGenerator(
name="holiday_sequence",
sequenceName="SQ_S_HOLIDAY"
)
public class Holiday {
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="holiday_sequence")
@Column(name = "ID_S_HOLIDAY", nullable = false, unique = true)
private Integer holidayId;
@Column(name="NAME_HOLIDAY")
private String holidayName;
@Column(name="IS_RECURRENCE")
private String isRecurrence;
@Column(name="IS_SKELETON")
private String isSkeleton;
@Column(name="CD_NAME_WEEK")
private Integer weekNameCode;
@Column(name="CD_NAME_DAY")
private Integer dayNameCode;
@Column(name="CD_NAME_MONTH")
private Integer monthNameCode;
@Column(name="DT_FIX")
private Date fixDate;
@Version
@Column(name="NO_CONCURRENCY")
private Long no_concurrency;
@Embedded
private BaseVO baseVo;
@OneToMany(fetch=FetchType.EAGER, mappedBy="holiday", cascade=CascadeType.ALL)
@org.hibernate.annotations.Cascade(value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
@PrimaryKeyJoinColumn(name="ID_S_HOLIDAY", referencedColumnName="ID_S_HOLIDAY")
@MapKey(columns=@Column(name="ID_S_HOLIDAY"))
private List<HolidayApply> holidayApplys;
public List<HolidayApply> getHolidayApplys() {
return holidayApplys;
}
public void setHolidayApplys(List<HolidayApply> holidayApplys) {
this.holidayApplys = holidayApplys;
}
public Holiday() {
this.baseVo = new BaseVO();
}
// PLUS the corresponding getters and setters
}
------------------------------------------------------------------------------
import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.MapKey;
@Entity
@Table(name = "S_HOLIDAY_APPLY2")
@javax.persistence.SequenceGenerator(name = "holiday_sequence2", sequenceName = "SQ_S_HOLIDAY")
public class HolidayApply implements Serializable {
private static final long serialVersionUID = 1296284153209538090L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "holiday_sequence2")
@Column(name = "id_s_holiday_apply2", nullable = false)
private Integer holidayId2;
@Column(name = "ID_S_Holiday")
private Integer holidayId;
@Column(name = "ID_S_CHOICE_APP", nullable = false)
private Integer choiceIdApp;
@ManyToOne(targetEntity = Holiday.class, cascade = CascadeType.ALL)
@JoinColumn(name = "ID_S_Holiday", referencedColumnName = "ID_S_Holiday", insertable = false, updatable = false)
@MapKey(columns = @Column(name = "ID_S_HOLIDAY"))
private Holiday holiday;
public Holiday getHoliday() {
System.out.println("Into HolidayApply getHoliday");
return holiday;
}
public Integer getHolidayId() {
System.out.println("Into HolidayApply getHolidayId");
return holidayId;
}
public void setHolidayId(Integer holidayId) {
System.out.println("Into HolidayApply setHolidayId");
this.holidayId = holidayId;
}
public void setHoliday(Holiday holiday) {
System.out.println("Into HolidayApply setHoliday");
this.holiday = holiday;
}
public Integer getHolidayId2() {
return holidayId2;
}
public void setHolidayId2(Integer holidayId2) {
this.holidayId2 = holidayId2;
}
public Integer getChoiceIdApp() {
return choiceIdApp;
}
public void setChoiceIdApp(Integer choiceIdApp) {
this.choiceIdApp = choiceIdApp;
}
}