Invalid hibernation warning? '@Access (AccessType.PROPERTY) in the field has no effect'

I have the following User entity class:

public class User implements Serializable { @Column(length = 10, name = "user_type") @Access(AccessType.PROPERTY) private String userTypeS; @Transient private UserType userType; ... public void setUserType(UserType userType) { this.userType = userType; this.userTypeS = this.userType.getType(); } protected void setUserTypeS(String userTypeS) { this.userTypeS = userTypeS; userType = UserType.toUserType(userTypeS); } 

UserType is an enumeration. This problem was that I couldn’t just use the @Enumerated annotation to display UserType, since the representation of the enumerations in the code is different from the representation in, for example:

 public enum UserType { CUSTOMER_NON_PRO("custnop") ... 

When working with an entity, I would like to specify enum as userType, not a string representation. To do this, I created a public setter that sets enum (userType) and translates it into a string representation (which is displayed with hibernation). Similarly, there is a protected setUserTypeS that must be called by hibernation and will map the user type String to enum UserType.

To do this, of course, hibernate must use setters to populate the object. In our project, it is preferable to set annotations on the properties of io getters / setters themselves. Therefore, hibernate will set property values ​​directly using introspection (and thus bypass the setters). For userTypeS, I indicated that the access type is PROPERTY (i.e., FIELD), and because of this sleep mode, setUSerTypeS is called.

It all works smoothly. The “problem” is that in our logs we see the following warning:

org.hibernate.cfg.AnnotationBinder - placing @Access (AccessType.PROPERTY) in a field has no effect.

This warning does not look right. If I removed @Access(AccessType.PROPERTY) from the userTypeS field, then hibernate will not call setter and therefore the userType enumeration will not be set. So the placement of @Access(AccessType.PROPERTY) affected.

Is this warning message invalid or outdated, or am I not understanding something?

thanks,
Stein

+7
source share
2 answers

@Access (AccessType.PROPERTY) is designed to be placed on a getter, for example:

 @Access(AccessType.PROPERTY) @Column(length = 10, name = "user_type") public String getUserType() { return this.userType.getType(); } public void setUserType(UserType userType) { this.userType = userType; } protected void setUserType(String userType) { userType = UserType.toUserType(userTypeS); } 

private String userTypeS; not required at all.

+7
source

I have no solution for you, but according to the JPA 2.0 specification (p. 26 footnote 8):

You cannot specify a field as access (PROPERTY) or property as Access (AREA)

+4
source

All Articles