Why should anybody put annotations on the getters or setters when using JPA to map the classes?

Putting annotations on methods forces JPA to access properties via methods. It makes sense when internal state of your object differs from the database schema: @Entity public class Employee { private String firstName; private String lastName; @Column(name = “EMP_NAME”) // Due to legacy database schema public String getName() { return fisrtName + ” ” + … Read more

When is @uncheckedVariance needed in Scala, and why is it used in GenericTraversableTemplate?

The problem is that GenericTraversableTemplate is used twice: once for mutable collections (where its type parameter should be invariant), and once for immutable collections (where covariance is invariably king). GenericTraversableTemplate’s typechecks assuming either covariance or invariance for the A type parameter. However, when we inherit it in a mutable trait, we have to pick invariance. … Read more

enable Annotation Processors option in Android Studio 2.2

Close the project. In the “Welcome to Android Studio” dialog click “Configure” in the bottom right corner. Then, Settings > Build, Execution, Deployment > Compiler > Annotation Processors. Tick ‘Enable annotation processing’. If that does not work. Delete the project from “Welcome to Android Studio” dialog and open from new. Worked for me.

RetentionPolicy CLASS vs. RUNTIME

both may be accessed at the run-time anyway. That’s not what the javadoc says: RUNTIME: Annotations are to be recorded in the class file by the compiler and retained by the VM at run time, so they may be read reflectively. CLASS: Annotations are to be recorded in the class file by the compiler but … Read more

BeanNotOfRequiredTypeException due to autowired fields

Somewhere in your code you must be autowiring AdminServiceImpl like this: @Autowired private AdminServiceImpl adminService; Either depend barely on interface: @Autowired private AdminService adminService; or enabled CGLIB proxies. Similar problems Autowired spring bean is not a proxy Fixing BeanNotOfRequiredTypeException on Spring proxy cast on a non-singleton bean? Getting Spring Error “Bean named ‘x’ must be … Read more

Android Retrofit Parameterized @Headers

Besides using @Header parameter, I’d rather use RequestInterceptor to update all your request without changing your interface. Using something like: RestAdapter.Builder builder = new RestAdapter.Builder() .setRequestInterceptor(new RequestInterceptor() { @Override public void intercept(RequestFacade request) { request.addHeader(“Accept”, “application/json;versions=1”); if (isUserLoggedIn()) { request.addHeader(“Authorization”, getToken()); } } }); p/s : If you are using Retrofit2, you should use Interceptor … Read more