My requirement is - based on the value of a flag(say for eg. skipDbUpdate) in properties file, I want to save/update the entities or skip these entities in the ongoing transaction. I have implemented a listener on the entity which will throw an exception if this flag is true, but now I have to enhance this behaviour to not throw an error but skip the update of the entity. I tried the below options :
- @Immmutable annotation on the entity - Im not able to make this flag based, application uses using spring but I'm not able to combine @ConditionalOnProperty annotation with @Entity and @Immutatble annotations.
@Entity @Immutatble public class EntityA {}
using updateable=false, insertable=false on each field of the entity inside @Column annotation - again, Im not able to make this flag based (same reason as above).
@Column(insertable = false, updatable = false)
Calling entityManager.detach(o) method inside the Listener when flag is true, as suggested in this question - How to make an Entity read-only? But this is trying to save the entities from other transaction and throwing the error - "
java.lang.RuntimeException: org.hibernate.HibernateException: Found two representations of same collection:
"
As this is old code base which uses spring only, I cannot use annotations that easily.
Please suggest which is the best possible way to fulfill this requirement?
Thanks