JPA question; How to delete child from parent entity
843830Jan 26 2010 — edited Feb 24 2010Hi 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;