-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Empty Collection set generating Update statement
PostPosted: Thu Jun 16, 2011 1:07 am 
Newbie

Joined: Thu Jun 16, 2011 12:03 am
Posts: 3
HI -

I am new to hibernate and I spent hours but not able to find a proper solution. I am hoping I will get some hints from experts.

I am loading the parent from XML file and the child is loaded with empty set. Before persisting the parent I check if the parent already exists using the PARENT_ID and in my case it find that the parent exists and there is one existing child record so when I do a em.merge() I am expecting that hibernate should delete the existing child records as the set is empty in the current parent but instead it is doing an update query which is throwing a NOT NULL exception.

Update CHILD_TABLE set PARENT_ID=null where PARENT_ID=?

Following is my code snippet of parent / child


@Entity
@Name("parent")
@Scope(ScopeType.SESSION)
@Table(name="Parent_Table")
public class Parent implements Serializable {

@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="tpGen")
@SequenceGenerator(name="tpGen", sequenceName="TP_SEQ")
@NotNull
@Column(name="SEQ_ID")
@Id
public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

@Column(name="PARENT_ID")
public String getParentId() {
return parentId;
}

public void setParentId(String parentId) {
this.parentId = parentId;
}


@OneToMany(targetEntity=Child.class, fetch=FetchType.EAGER, cascade=CascadeType.ALL)
@JoinColumn(name="PARENT_ID", referencedColumnName="PARENT_ID")
@NotFound(action=NotFoundAction.IGNORE)
@Cascade({org.hibernate.annotations.CascadeType.PERSIST, org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
public Set<Child> getChildSet() {
return childSet;
}



}

---------------------------------------------------------

Child Class
-----------


@Entity
@Name("Child")
@Scope(ScopeType.SESSION)
@Table(name="Child_Table")
public class FileNamingTemplateMembership implements Serializable {



private transient String parentId;
private String templateName;

private transient String updateUserId;
private transient Date updateDate;


@Id @NotNull
@Length(max=80)
@Column(name="PARENT_ID")
public String getParentId() {
return parentId;
}

public void setParentId(String parentId) {
this.parentId = parentId;
}

@Length(max=40) @NotNull
@Column(name="CHILD_NAME")
public String getChildName() {
return childName;
}

public void setChildName(String childName) {
this.childName = childName;
}

@Length(max=80)
@Column(name="UPDT_USER_ID")
public String getUpdateUserId() {
return updateUserId;
}

public void setUpdateUserId(String updateUserId) {
this.updateUserId = updateUserId;
}

@Column(name="UPDT_DT")
public Date getUpdateDate() {
return updateDate;
}

public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}

}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.