Avoid updating parent record when child objects merged

Usually in cascading, when the parent is set with collection of child objects and merged using session.saveOrUpdate(parent) or entityManager.merge(parent) , it usually updates the parent record after child records were inserted. This can be avoided using “updatable=false”.

@ManyToOne( fetch = FetchType.LAZY )
@Cascade( {CascadeType.PERSIST, CascadeType.MERGE} )
@JoinColumn( name = "<PARENT_ID>", updatable = false, 
                   referencedColumnName = "<PARENT_ID>" )
private Parent parent;
 
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: