Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JPA question; How to delete child from parent entity

843830Jan 26 2010 — edited Feb 24 2010
Hi all!
I'm having some trouble with JPA and deleting children from a parent entity.
Here's the situation: I made a entity App. This has a one-to-many relationship to ServerInstance.
My question is; How can I delete a ServerInstance from the App. I tried deleting a ServerInstance directly from my ManagedBean (Sessionscoped), but then the App still holds on to the deleted ServerInstance.
Is there a way to delete a ServerInstance from within the App entitiy?

Here are the entities:

App:

public class App implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Integer id;
private String appname;
private String description;
private String environment;
@OneToMany (fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
private List<ServerInstance> serverInstance = new ArrayList<ServerInstance>();

ServerInstance:

public class ServerInstance implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Integer id;
private String instancename;
private String home;
private String hostname;
private String ipfront;
private String ipback;
private String layer;
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 24 2010
Added on Jan 26 2010
6 comments
2,108 views