I've one persistent class that has one transient field representing the API version of this class (subset of the fields that I user for api requests). This field is @Transient
as I simple use the other fields to create it.
The problem is that hibernate uses the default empty constructor to instantiate the class and reflection to access the fields... so i can't instantiate my transient class on constrorctor nor on the call of setter methods
I tried to anotate the getter method instead of the field to force hibernate to use the setter, but it didn't work
I tried to use @Access(AccessType.PROPERTY)
on the fields but it didn't work
how to force hibernate call setter methods to fill class fields?
@Entity
public class User {
@Transient
private ApiUser tempUser = new ApiUser ();
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Access(AccessType.PROPERTY)
@Column(nullable = false)
private String name;
@Access(AccessType.PROPERTY)
@Column(nullable = false, unique = true)
private String username;
@Access(AccessType.PROPERTY)
@Column(nullable = false)
private String userId;
//lots of others fields//
public void setUsername(String username) {
this.username = username;
this.tempUser.setUsername(username);
}
public void setUserId(String userId) {
this.userId = userId;
this.tempUser.setId(Long.parseLong(userId));
}