Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate case sensitive columns with JPA in MySQL automatically

Tags:

java

mysql

jpa

How can I order JPA to set a MySQL database column with text content as case sensitive by default upon creation?

like image 865
ali Avatar asked Jul 01 '10 19:07

ali


People also ask

How do I make MySQL database case-sensitive?

To set the collation for the entire database, you can use: CREATE DATABASE test_database CHARACTER SET utf8 COLLATE utf8_general_cs; You can also change the collation on an existing database via ALTER DATABASE. (For more information see the MySQL Database Character Set and Collation manual entry.)

Are JPA queries case-sensitive?

Spring Data JPA queries, by default, are case-sensitive. In other words, the field value comparisons are case-sensitive.

Is MySQL case-sensitive by default?

By default, it depends on the operating system and its case sensitivity. This means MySQL is case-insensitive in Windows and macOS, while it is case-sensitive in most Linux systems. However, you can change the behavior by changing collation.

Are columns in MySQL are case-sensitive?

Column, index, stored routine, and event names are not case-sensitive on any platform, nor are column aliases. However, names of logfile groups are case-sensitive.


1 Answers

The @Column annotation on your field can specify a columnDefinition attribute which may allow you to specify a case-sensitive collation for the column.

public abstract String columnDefinition

    (Optional) The SQL fragment that is used when generating the DDL for the column.
    Defaults to the generated SQL to create a column of the inferred type.
    Default:
        ""

In your case, for example, using the @Column annotation, you would use

@Column(name = "NAME_COL", columnDefinition = "VARCHAR(250) COLLATE latin1_general_cs")
private String name;
like image 88
jbindel Avatar answered Sep 28 '22 09:09

jbindel