简体   繁体   中英

Hibernate - Cascading type from annotations to hbm.xml

I'm currently asked to convert our POJOs hibernate annotations to hbm.xml files,

But I came across two annotations that I can't "translate" and doesn't find a complete answer to my question,

What cascading type should I use to reflect the following: 1)

@Cascade({CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.REMOVE, CascadeType.SAVE_UPDATE })

2)

@Cascade({CascadeType.MERGE})

Thanks in advance.

.hbm.xml file have 6 types of cascade annotations.

  • First type is cascade="none" - the default type. It tells Hibernate to ignore the associations.
  • Second type is cascade="save-update" - that type tells Hibernate to navigate the association when the transaction is committed and when an object is passed to save() or update() and save newly instantiated transient instances and persist changes to detached instances.
  • Third type - cascade="delete" which tells Hibernate to navigate the association and delete persistent instances when an object is passed to delete().
  • Fourth type is cascade="all" - which tells Hibernate to cascade both save-update and delete, as well as calls to evict and lock.
  • Fifth cascade="all-delete-orphan" means the same as cascade="all" but, in addition, Hibernate deletes any persistent entity instance that has been removed (dereferenced) from the association (ie: from a collection).
  • Sixth - cascade="delete-orphan" tells Hibernate to delete any persistent entity instance that has been removed (dereferenced) from the association (ie: from a collection).

I hope this information will help you. You just need to choose what you really need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM