Hi,
I am new to Hibernate. I am facing issue mapping related issue. Following are the details.
I have scenario where evtEvent entity is related to edocEventDocument entity such that one evtEvent can have many edocEventDocument.
My problem is that, when I add new object into collection and then call save method of evtEvent object then that new objects are inserted accordingly in edocEventDocment table. but when I remove few object from document collection then accordingly that rows are not deleted from edocEventDocument table.
Can anyone please help me to understand what I am doing wrong?
Following is the table structure.
evt_event(
evt_code (primary key)
)
edoc_evt_document(
edoc_version,
edoc_evt_code( foreign key from event table)
)
Following is the Event entity
Code:
@Entity
@Table(name = "evt_event", schema="tmpdev")
public class EvtEvent implements java.io.Serializable {
private String evtCode;
private Set<EdocEvtDocument> edocEvtDocuments = new HashSet<EdocEvtDocument>(0);
@Id
@Column(name="evt_code", unique=true, nullable=false, length=20)
public String getEvtCode() {
return this.evtCode;
}
public void setEvtCode(String evtCode) {
this.evtCode = evtCode;
}
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="evtEvent")
public Set<EdocEvtDocument> getEdocEvtDocuments() {
return this.edocEvtDocuments;
}
public void setEdocEvtDocuments(Set<EdocEvtDocument> edocEvtDocuments) {
this.edocEvtDocuments = edocEvtDocuments;
}
}
Following is the EdocEvtDocument
Code:
@Entity
@Table(name = "edoc_evt_document", schema = "tmpdev")
public class EdocEvtDocument implements java.io.Serializable {
private Integer edocVersion;
private EvtEvent evtEvent;
@Id
@Column(name = "edoc_version", unique = true, nullable = false)
public Integer getEdocVersion() {
return this.edocVersion;
}
public void setEdocVersion(Integer edocVersion) {
this.edocVersion = edocVersion;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "edoc_evt_code", nullable = false)
public EvtEvent getEvtEvent() {
return this.evtEvent;
}
public void setEvtEvent(EvtEvent evtEvent) {
this.evtEvent = evtEvent;
}
Thanks,
Rohit