JPA CascadeType priority? -


using jpa have question relating cascadetypes.

for example:

@manytomany(fetch=fetchtype.lazy, cascade={cascadetype.persist, cascadetype.merge, cascadetype.refresh}) 

is different this:

@manytomany(fetch=fetchtype.lazy, cascade={cascadetype.merge, cascadetype.persist, cascadetype.refresh}) 

why? need cascadetype persist automatically insert referenced objects in entityclass. , need merge because dont want have double entries in tables. when define persist first, merging doesnt work, when define merge first, persist doesnt work.

why?

the jpa specification readable document , can downloaded here:

https://jcp.org/aboutjava/communityprocess/final/jsr317/index.html

inside on page 384 covers cascade attribute of manytomany annotation:

the cascade element specifies set of cascadable operations propagated associated entity. operations cascadable defined cascadetype enum: public enum cascadetype { all, persist, merge, remove, refresh, detach}; value cascade=all equivalent cascade={persist, merge, remove, refresh, detach}.

as can see says nothing order. happening application using new object needs persisted , loading 1 database needs merged. in order words, application issue.

personally use diy approach merging entities in persistence context. article read on subject here:

http://blog.xebia.com/2009/03/23/jpa-implementation-patterns-saving-detached-entities/


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -