egzaell
egzaell

Reputation: 195

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?

Upvotes: 3

Views: 10707

Answers (2)

SkyWalker
SkyWalker

Reputation: 29130

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

Upvotes: 3

thommyberglund
thommyberglund

Reputation: 104

This problem was a similar one but with Spring Boot + Hibernate + SQL Server. Check the solution and see if you can apply something similar.

Hibernate @Column annotation not work

Upvotes: 0

Related Questions