문제

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;
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top