I have a transactional entity associated to another entity whereby the associated should not be updated in an case.
Eg. Case *-> User
Where a Case is owned by a User and reversely a User can have many associated Case.
The association is mapped using OneToMany and JoinColumn JPA annotations.
I have also tried marking the Trasactional annotation for User entity as readonly and also made the fetch methods Transient. But this doesnot seem to stop update on User if its state is changed.
Please help me a figure a way to declare a “read-only” association to User.
You can add
updatable=falseon @JoinColumn annotation.Furthermore you should not add a setter method for
userin yourCaseentity and same forcaseSetin yourUserentity. The gettergetCaseSetinUserentity should also return an unmodifiable collection: