views:

32

answers:

1

What cache concurrency strategy should be used for @ManyToOne fields for a particular entity class. Would it make sense to use READ_ONLY instead of READ_WRITE, since these fields usually don't change after entity creation

@ManyToOne(fetch = FetchType.LAZY)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
...
private User user;
+1  A: 

If these fields "usually don't change" as opposed to "never change", then READ_ONLY is not an option. The other cache concurrency strategies offer different tradeoffs between database throughput and transaction integrity. The choice would depend on your particular circumstances and requirements.

btreat
the primary key id for these fields will definitely not change, but the content might change. But none of the UI pages show information from these fields (i.e. they primarily exist only because of foreign key constraints). So will READ_ONLY be a good choice?
Samuel
If the data can't change while the application is running, READ_ONLY should be just fine. Otherwise, I'd recommend using READ_WRITE or something else.
btreat