3

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?

3
  • 1
    Please display how you have been add new data? Commented Jan 3, 2018 at 12:22
  • You could just add "@id" before "@Column" Commented Jan 3, 2018 at 12:23
  • I'm inserting data using Spring Data JPA repositories, and yup this entity has an @Id. Commented Jan 3, 2018 at 12:28

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

2 Comments

sorry, it was almost 2 years ago, and I can't remember how I solved this issue, so I can't mark your answer.
@egzaell Actually I got same error and fixed this issue. I have made some R&D and got this two approaches to resolve the issue. So I am here to share my knowledge.
0

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

1 Comment

Thanks but it's something new, I'm working in a big app, and problem is with just these new columns.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.