EclipseLink no elimina el elemento uno a varios de propiedad privada

I am unable to get Eclipselink to delete a privately owned entity that is mapped as a one-to-many relationship. When I remove the privately owned entity from the one-to-many collection and set the reference to its parent to NULL and then save the parent, the privately owned entity is not removed from the database. However, it is removed from the object and during the remainder of the session, it appears that the privately owned entity was in fact removed.

Here's one mapping

@OneToMany(mappedBy="parent", cascade={CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH}, fetch=FetchType.EAGER)
@PrivateOwned // should prevent orhpans, but doesn't.
List<PrivatelyOwnedEntity> privatelyOwnedEntities;

I have tried adding cascade all, and also added @CascadeOnDelete, and every combination thereof, which one would think would not have an impact, and it didn't.

otherside:

@ManyToOne
private Parent parent;

I have tried adding JoinColumn(nullable=false) and also removing the @ManyToOne annotation, and every combination of the presence/removal of these annotaitons. None of the changes had any impact.

Removal code:

public boolean removePrivatelyOwnedEntity(int i) {
    PrivatelyOwnedEntity privatelyOwnedEntityToBeRemoved = this.privatelyOwnedEntities.get(i);
    //privatelyOwnedEntityToBeRemoved.setParent(null); 
    return this.privatelyOwnedEntities.remove(privatelyOwnedEntityToBeRemoved );
}

Code that updates:

projectManager.saveProject(project);
//so this privatelyOwnedEntity is deep within this object.
// Its project.site.siteMap.parents.privatelyOwnedEntities.
// SiteMap is embedded in Site.
// On save it calls a dao, and the dao's abstract class handles the update
// as shown below using Springs JpaTemplate

Guardar código:

public T save(T object) {
    return getJpaTemplate().merge(object);
}

preguntado el 08 de noviembre de 11 a las 19:11

Can you show the code used to read in the parent, make the change and persist it? -

Sure, I added the additional code above -

1 Respuestas

Is the parent part of the object's id?

Try not setting the parent to null, you should not do this for private owned objects, just remove them from the collection.

respondido 15 nov., 11:23

Thanks for your response. Unfortunately, that did not work. Any other ideas? I'm not sure what you mean by "Is the parent part of the object's id" The privately owned entity uses Identity strategy for id. @GeneratedValue(strategy=GenerationType.IDENTITY) - Ceniza

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.