Search code examples
jpaeclipselink

programmatically make all relationships CascadeType.MERGE


We have strictly defined which relationships are CascadeType.MERGE in our app. This plays into our version checking (optimistic locking). So, our CascadeType definitions sometimes have MERGE and sometimes not. This is all great for our OLTP application. However, we also have a requirement to load in data (fine to do it batch offline) in which the relationships might be different. What I'd like to do is tell jpa (or eclipselink) to treat every relationship as CascadeType.MERGE during this batch load. In other words, I want eclipselink to ignore our annotations during this batch load. Is this possible?


Solution

  • The JPA standard defines two ways to configure the entities - annotation, which every one know, and XML files. The definition in the XML should override the annotation definition. It means you have two options:

    • Write the XML files by hand
    • Write a small program that will read your entities and (by reflection) generate the XML file.

    You can find examples for the orm.xml file here