-->
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: Annotation-OneToMany-Child record not deleted frm the collec
PostPosted: Sat Sep 24, 2011 5:44 am 
Newbie

Joined: Fri Sep 23, 2011 7:39 pm
Posts: 1
Hi,

I use Hibernate 3.6.4 with JPA 2 .
I have OneToMany similar to the below code:

1. Parent Class:

@Entity
@Table(name = "PARENT_TABLE")
public class Parent implements Serializable{

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_IC_PARENT")
@SequenceGenerator(name = "SEQ_IC_PARENT", sequenceName = "SEQ_IC_PARENT", allocationSize = 1)
@Column(name = "PARENT_ID")
private Integer parentId;

@Column(name = "PARENT_NAME")
private String parentName;

@OneToMany(mappedBy="parent",
targetEntity = Child.class, cascade = { CascadeType.PERSIST, CascadeType.MERGE,CascadeType.REMOVE,CascadeType.DETACH,CascadeType.REMOVE,CascadeType.REFRESH},
orphanRemoval=true)
@Cascade( { org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.MERGE,
org.hibernate.annotations.CascadeType.DELETE,
org.hibernate.annotations.CascadeType.PERSIST,
org.hibernate.annotations.CascadeType.DELETE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
private List<Child> ChildList = null;

}

2. Child Class

@Entity
@Table(name = "CHILD")
public class Child implements Serializable{
@Id
@Column(name="CHILD_ID")
private String childId;
}

3. Parent Child Class:

@Entity
@Table(name = "PARENT_CHILD")
public class ParentChild implements Serializable{

@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator ="SEQ_IC_BD_SUPPORT")
@SequenceGenerator(name="SEQ_PARENT_CHILD", sequenceName="SEQ_PARENT_CHILD", allocationSize=1 )
@Column(name = "PARENT_CHILD_ID")
private Integer parentChildId;

@ManyToOne
@JoinColumn(name = "parent_id",insertable=false,updatable=false)
private Parent parent;

@OneToOne
@JoinColumn(name = "USER_ID")
private Child child;
}

Basically I have 3 tables. Parent, Child and Parent_Child.

When saving the list in parent class, the child records are not deleted when i remove them from the collection.

Can you let me know If I am missing any in the mapping?

On Save I do this:

transaction = session.beginTransaction();
session.save(parent); or session.update(parent);
session.flush();
transaction.commit();


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.