I have a problem on the following situation:
In my Spring, Hibernate application I got a User Entity and a UserCategory Entity. The table of the user entity got a username as identifier. This indentifierfield can't be encrypted because this table is also used by an older program without the possibility to do this.
To make a ManyToOne reference from UserCategory to User I need a field in the UserCategory table with the unique username of a User. What I want to do is to encrypt the username in the UserCategory table using Jasypt. And of course this work:
@Type(type="encryptedString")
@ManyToOne
@JoinColumn(name = "username", insertable=false, updatable=false)
@ForeignKey(name = "none")
public User getUser(){
return this.user;
}
public void setUser(User user ){
this.user = user;
}
But after putting the username encrypted in the UserCategory table I can't use this record because Hibernate can't make a reference to the User on encrypted field: You will get the following error:
"No row with the given identifier exists: com.foo.bar.models.User#M9LgndiyCsVGqfVRVblb3A=="
This is a logical error, but do you know a good solution. In think the code need something to first decrypt and then try to make the reference. But I'm stuck on how to do this.