Save object with uppercase vs lowercase letter

I think I had posted a question previously equal to this, but I didn't find it.

I have a manufacturer entity where I want to persist, to avoid differentiating upper and lower case letters, can I save an object with all uppercase or lowercase? Is that good practice?

Author: Caffé, 2017-03-28

1 answers

We are here dealing with the persistence of objects coming from the browser. We need to ensure that in the database there is no difference between the manufacturer's name all in high box or all in low box.

Assuming that the information entered by the user is the right one most of the time, we should not (most of the time) get our hands on the data and make a coercion on it. Not even the coercion of forcing high/low box.

Ideally, the DBMS treats this column as case insensitive / case insensitive . You can specify how the column will be created using the columnDefinition annotation @Column property. For example, in international OS, they made an example of changing the collation from a column to latin1_general_cs.

In the case of MySQL, there are several patterns of collate and ways to place in a column. If the value of collate is omitted, it will use the default for the table; if this is also omitted, it will use what is configured in the bank.

In our case, we want to make sure that it will be insensitive to the case, so we can put in the column:

// baseado no exemplo do link do SO internacional
@Column(name = "NAME_COL", columnDefinition = "VARCHAR(250) COLLATE latin1_general_ci")
private String name;

Recommended Reading:

 1
Author: Jefferson Quesado, 2018-03-05 22:16:58