I have a set of related tables with a minimal amount of data that changes slowly (weekly) and I would like to use Hibernate to load it into a class tree. These objects would then participate in highly concurrent, read-only environment (a web service).
I'm reading _Java Concurrency in Practice_ by Brian Goetz. Based on my reading, a completely immutable class would look like this:
Code:
public class Book {
private final String name;
private final Long id;
public Book(String n, Long i) {
name = n; id = i;
}
public String getName() { return name; }
public Long getId() { return id; }
}
Unfortunately, it is not possible to add a no-arg constructor to this because the instance vars may not have been initialized. Also, using
final variables means that they cannot be initialized with a set method, so Hibernate would need to initialize the final field values via reflection - is this construction even possible with Hibernate??
In general, are there any guaranties that field values written by Hibernate (either by set methods or field reflection) are visible to other threads? Using the
volitile keyword is supposed to ensure values are always written back to the heap - should volitile be used for fields of domain objects managed by Hibernate?
Thanks,
--ee