Save object with uppercase vs. lowercase letter

1

I think I had posted a question earlier than this, but I did not find it.

I have a Manufacturer entity where I want to persist, to avoid differentiating between uppercase and lowercase letters, can I save an Object with all capital letters or lowercase letters? Is this a good practice?

    
asked by anonymous 28.03.2017 / 03:51

1 answer

1

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 name of the Manufacturer in the whole box and all in the box.

Assuming that the information entered by the user is the right one most of the time, we should not (mostly) get their hands on the data and coerce them. Not even the coercion of forcing high / low cash.

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

In the case of MySQL, there are several standards for collate and ways to put yourself on a column . If the collate value is omitted, it will use the default for the table; if this is also omitted, it will use what is set up in the database.

In our case, we want to make sure that it will be insensitive to the case, so we can put it 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:

28.03.2017 / 05:15