'how to make values of column in entity class as lower case while storing using Annotation

I want an entity class through which I can store data to DB, for specific columns I want in case-sensitive, is there any annotation to be used above these specific columns to store as requested? please let me if the question is not clear,Thanks in advance.

@Column(name = "EMAIL",unique=true)  //i want store this email id as lower case,
private String email;               //never mind in what case user enters


Solution 1:[1]

You can do this using @ColumnTransformer

 @Column(name = "email") 
@ColumnTransformer(write = "LOWER(email)") 
 private String email;

Solution 2:[2]

I try this and it works:

@Column
@ColumnTransformer(write = "LOWER(?)") 
private String email;

expression of @ColumnTransformer.write would replace the original "?" placeholder in persisting sql statement. So must provide a compliant-sql expression with "?":

insert into member (email) values (?)

---->

insert into member (email) values (LOWER(?))

detail usage: https://docs.jboss.org/hibernate/orm/5.4/javadocs/org/hibernate/annotations/ColumnTransformer.html

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 GnanaJeyam
Solution 2