Hibernate version:
hibernate3.jar & hibernate-tools.jar from JBossIDE-N200509280156-ALL
part of Waterbdy.hbm.xml
Code:
<set name="sites" inverse="true">
<key>
<column name="llid_no" length="13" not-null="true" />
</key>
<one-to-many class="Site" />
</set>
Generated domain models are behaving differently regarding the value of
the attribute known as ejb3 ;-)
For the above mapping, note that Site (the many side) is the relationship owner . If I deploy this all is well. However, if I leave out the mapping document, and set
the attribute known as ejb3 to true, here is the generated java ...
Code:
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "llid_no")
public Set<gov.blm.ak.arims.generated.Site> getSites() {
return this.sites;
}
This relationship behaves much differently - taking transient Waterbdy instances into a persistent state w/ an update tries to delete all related Sites - whereas the mapping document instructs H to ignore this. This is fixed if I manually make the following change to the @OneToMany annotation:
Code:
@OneToMany(mappedBy="site", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
1.) Is it correct to say that mappedBy="site" for @OneToMany is analogous to inverse="true" in the set element in the hbm.xml ? I say this because the following is in the dox.
Code:
To declare a side as not responsible for the relationship, the attribute mappedBy is used
2.) If so, shouldn't the tool generate 'mappedBy' if inverse="true" ?
3.) Can someone please reconcile these two discrepencies in the documentation?
Code:
The rules you have to remember are straightforward: All bi-directional associations need one side as inverse. In a one-to-many association it has to be the many-side
Code:
Since many to one are (almost) always the owner side of a bidirectional relationship
why the almost? how the almost?