Hibernate version: 3.2.4
I'm working on a solution which pulls data from an foreign XML source into objects which are then persisted in the database.
The XML is simple:
Code:
<data>
<widget id="A"/>
<widget id="B"/>
<widget id="C"/>
</data>
OK, so this XML maps to a Data object which contains a Set of Widget objects. Since these are detached objects, I call merge() to save/update them in my database.
Code:
// JAXB mappings here as well
@Entity
public class Data implements Serializable {
// JAXB mappings here as well
@OneToMany( cascade = {CascadeType.ALL} )
private Set<Widget> widgets = new HashSet<Widget>();
[...]
}
Merge:
Code:
Data dataJAXB = (Data) getUnmarshaller().unmarshal(
new File( path )
);
DataDAO dao = getFactory().getDataDAO();
Data dataHIB = dao.findById( dataJAXB.getId(), true );
dao.merge( dataJAXB );
[...]
My problem is that I may not receive every widget tag but that doesn't mean it has been deleted.
I understand that I'm merging the current state in the XML file but is there a way I can specify the Cascade to always Save/Update existing but never remove a missing (in the XML file) association? I'll have logic further down the line which handles widgets which actually need to be disabled.
Any insight is greatly appreciated,
BG4