-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Cascading, annotations, and Eclipse IDE
PostPosted: Tue Nov 06, 2007 7:43 pm 
Newbie

Joined: Tue Nov 06, 2007 6:51 pm
Posts: 4
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 07, 2007 3:15 pm 
Newbie

Joined: Tue Nov 06, 2007 6:51 pm
Posts: 4
I think I figured this out.

1) The Hibernate tools do not generate the correct hbm.xml files.
2) The Hibernate tools do not generate the correct hibernate.cfg.xml file.
It converts "mapping class" to "mapping resource"!
3) The solution is to not have the tools generate these files.
Simply copy the hibernate.cfg.xml (using "mapping class") to the 'bin'
folder. That way, Hibernate will (apparently) use reflection to gather the
annotation parameters rather than the incorrectly generated hbm.xml files.
You just have to remember to do this after every change...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.