Skip to content
Advertisement

Hibernate Null Attribute Value using Camel-Case

Using

Hibernate 5.3, Spring Boot 2.1, MySQL, that runs in Windows 10 OS.

What I know

I have verified on my phpmyadmin the case of the attributes. And as long the case were the same as the attributes of my Entity class you don’t have to explicitly define the column name in that Entity. And using @Column(name="tableattribute") is not required.

Problem

Once I executes the query, the number of row has been retrieved correctly. For example, my database contains 5 record, the List contains 5 employee objects, but all its attributes of the Entity always returns as null value.

I want to remove explicitly declaring the column name on each attribute and ensure that it will work in the actual server which might cause problem with the case of column name and the attribute name.

Tried

I tried to add @Column('column Name all lowercase') on each attributes and It retrieve the value.

Upon learning this, I verified the table column if it is lower case, but is not in lower case. Instead, It still follow the camel-case that is in my SQL command to create the table.

MySQL Table

Entity

This Entity is now working fine as long as @Column and specify the column name in lowercase. But it is annoying to add each attribute with @Column and specify the name of the field in all lower case.

Actual Query Snippet on DAO

Advertisement

Answer

You can change that behavior by setting

properties in your application.properties. On how to implement the strategies yourself, you can check out official docs.

Edit 1:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement