views:

281

answers:

1

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?

Thanks,

Ben

+2  A: 

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

David Rabinowitz
If I don't get any other answers, I'll accept this. "Write a small program that will read your entities and (by reflection) generate the XML file." - I was hoping that I didn't have to do something that ugly. The more I use JPA, the more I realize how much it is lacking!
andersonbd1
You can always can do it by hand... This is the price of flexibility. If we could have ActiveRecord like ruby, we would have less flexibly configuring the relation between the objects and the database (and you can argue both ways if it is good or bad)
David Rabinowitz
I don't agree that it's the price of flexibility. I believe it's a possible feature that just hasn't been implemented.
andersonbd1
It may be possible to have programmatic configuration for the JPA provider, but I'm not aware of any (never needed one). All the major providers are open source, so you can add one yourself.
David Rabinowitz