views:

30

answers:

1

I was wondering if my idea is possible with hibernate.

What I want is that there is one table with usernames and every table wich has a reference to this table has the username encrypted in a column. So the username doesn't stand in normal text but encrypted in every table which have a reference to the user table.

So I need something like:

@ManyToOne
@JoinColumn(name = "userName", insertable=false, updatable=false, encrypted="md5")
public User getUser(){
    return this.user;
}
public void setUser(User user ){
    this.user = user;
}

I hope that I make myself clear.

+1  A: 

You should implement this using a custom UserType and Jasypt (Java Simplified Encryption) actually provides a basic set of Hibernate UserType that may suit your needs.

See also

Pascal Thivent
Sounds as a solution, but I can't found anything about a @oneToMany and that one side is ecrypted. So in the usertable is no encryption on username but for example on userCategories there is. Do you think this is possible? thx
michel
@michel I didn't pay enough attention to the question and should have mentioned that in my answer but the idea is to encrypt basic types, not entities (i.e. the `username` in the `User`, not the `User` entity itself).
Pascal Thivent
I don't want to encrypt whole entities but only the reference fields. but I don't think this is gonna work. I send a request to the developers of Jasypt. The @ManyToOne is not gonna work because he tries to resolve the User entity before decrypting. get the error: "No row with the given identifier exists: com.foo.bar.models.User#M9LgndiyCsVGqfVRVblb3A==" thx for your answer
michel