I'm new to this hibernate annotation. I want to convert this xml mapping into annotations:
<map name="Text" table="JAV_TEXT" inverse="true" cascade="all-delete-orphan">
<key column="FK_GUID"/>
<map-key column="TEXT_GUID" type="string"/>
<one-to-many class="com.TextPO"/>
</map>
This is what I have done:
@OneToMany(fetch = FetchType.LAZY, targetEntity=com.TextPO.class)
@Cascade({CascadeType.DELETE_ORPHAN})
@JoinColumn(name="FK_GUID")
@MapKey(name="TEXT_GUID")
private Map<String, PersistentObject> text = new HashMap<String, PersistentObject>();
But CascadeType.DELETE_ORPHAN
is deprecated, so how do I represent all-delete-orphan
through annotations?
I'm using hibernate 4.1.4.
Yes in
Hibernate 4.1.4
versiondelete-orphan
is deprecated, now inHibernate
andJPA 2.0
you can useorphanRemoval
instead:Your mapping should be like this:
And also remove the
@Cascade
annotation you can use it as an attribute of the@OneToMany
annotation like this:Take a look at this Example for further reading.
EDIT:
To give the
inverse="true"
property in your mapping you just need to specify themappedBy
attribute in your @OneToMany
annotation to refer the owning part of the relation, like this:Here the
theOneSide
is used as an example you just need to specify the field name used in the other side class of the mapping, for example:Take a look at inverse=true in JPA annotations for further information.