[英]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.我的问题是我在 SQL Server 2016 中有 2 个架构,但具有相同的表。 I've altered both, and added 3 same columns each.
我已经更改了两者,并分别添加了 3 个相同的列。 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 中添加的名称相匹配。
@Column(name = "claim_number", nullable = true, length = 30)
private String claimNumber;
Any ideas?有什么想法吗?
Caused by: java.sql.SQLException: Invalid column name 'claim_number'.引起:java.sql.SQLException:无效的列名“claim_number”。
Issue Analysis:问题分析:
If we check the column name, we will find that,如果我们检查列名,我们会发现,
i) it contains underscore("_"). i)它包含下划线(“_”)。
Solution#1:解决方案#1:
Hibernate uses various type of naming strategy. Hibernate 使用各种类型的命名策略。 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
NB: For checking the error, you can add the following properties in application.properties file.注意:为了检查错误,您可以在application.properties文件中添加以下属性。 It will show sql in console and you can make decision.
它将在控制台中显示 sql,您可以做出决定。 So please add it:
所以请添加它:
# Show or not log for each sql query
spring.jpa.show-sql = true.
Caused by: java.sql.SQLException: Invalid column name 'claimnumber'.引起:java.sql.SQLException:无效的列名“claimnumber”。
Issue Analysis:问题分析:
If we check the column name, we will find that,如果我们检查列名,我们会发现,
i) it contains lowercase string . i) 它包含小写字符串。 No underscore.
没有下划线。
Solution#2:解决方案#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.
这时候就需要用到hibernate的另一种命名策略了。
# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
This problem was a similar one but with Spring Boot + Hibernate + SQL Server.这个问题与 Spring Boot + Hibernate + SQL Server 类似。 Check the solution and see if you can apply something similar.
检查解决方案,看看您是否可以应用类似的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.