Hibernate 3.2.5.ga
Annotations 3.3.0.ga
Tools 3.2.0.b9 (on Eclipse 3.3) (couldn't get b11 to work at all...)
Trying to model a basic parent/child structure with cascading load and save.
(
http://www.hibernate.org/hib_docs/v3/re ... d-cascades)
Extensive searching through tutorials finds two possible ways:
@OneToMany(fetch = FetchType.LAZY, cascade = javax.persistence.CascadeType.ALL)
@org.hibernate.annotations.Cascade(value = {org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
private List<Project> children;
and
@org.hibernate.annotations.Cascade(value = {org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
@CollectionOfElements(fetch = FetchType.LAZY)
private List<Project> children;
Neither of these cases seems to work for me.
A look at the generated (by Hibernate tools) hbm.xml file shows no "cascade" tag. Adding this manually appears to fix it, but since this file is generated, I would prefer not to do this.
Interestingly, if I use a ManyToOne from child to parent with "cascade", it *is* reflected in the generated hbm.xml file...
Is there something fundamentally wrong with my approach?
Or a bug in the tools?
Alternatively, I figured I might be able to modify the cascade value programmatically in the SessionFactory Metadata. However, when I looked at the Metadata in the debugger, the cascading seems to already be properly set!
What gives?
I don't see another generated file that might hold this info anywhere...
Many thanks to anybody who wants to help a newby learn Hibernate,
Scott