Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate, SQL Server 2016 = SQL Error: 207 - Invalid column name

my problem is that I have 2 schemas in SQL Server 2016, but with the same tables. I've altered both, and added 3 same columns each. But when hibernate wants to add new data to this altered tables it gives me an exception

Caused by: java.sql.SQLException: Invalid column name 'claim_number'.

And yes, name of columns matches the names added in @Column.

@Column(name = "claim_number", nullable = true, length = 30)
private String claimNumber;

Any ideas?

like image 750
egzaell Avatar asked Jul 07 '26 16:07

egzaell


1 Answers

Problem#1:

Caused by: java.sql.SQLException: Invalid column name 'claim_number'.

Issue Analysis:

If we check the column name, we will find that,

i) it contains underscore("_").

Solution#1:

Hibernate uses various type of naming strategy. It the column contains underscore, then we need to use the following naming strategy.

spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

N.B: For checking the error, you can add the following properties in application.properties file. It will show sql in console and you can make decision. So please add it:

# Show or not log for each sql query
spring.jpa.show-sql = true.

Problem#2:

Caused by: java.sql.SQLException: Invalid column name 'claimnumber'.

Issue Analysis:

If we check the column name, we will find that,

i) it contains lowercase string. No underscore.

Solution#2:

Sometimes developers create a table with columns which contains only lowercase string. On that time we need to use another naming strategy of hibernate.

# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
like image 72
SkyWalker Avatar answered Jul 10 '26 04:07

SkyWalker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!