Question

The new feature for type safe queries generates a metamodel for the classes, but why these fields aren't final instead of volatile ?

public static volatile SingularAttribute<Presentation, String> topic;
Was it helpful?

Solution

Fields in metamodel class cannot be final, because static final field should be assigned:

  1. together with the declaration or
  2. in static initializer.

This cannot be done, because value that should be assigned is not known to the one that creates metamodel class. Values are assigned by provider when EntityManagerFactory is created.

Consequence is that attributes must be volatile to guarantee that other threads can see values assigned by provider.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top