ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelpe / org.springframework.dao.InvalidDataAccessResourceUsageException: JDBC exception executing SQL

huangapple go评论53阅读模式
英文:

ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelpe / org.springframework.dao.InvalidDataAccessResourceUsageException: JDBC exception executing SQL

问题

以下是运行时生成的JPA查询:select m1_0.Patient_Id,m1_0.PLN_ID from [DevDatabase.dbo].Users m1_0 where m1_0.Patient_Id=?

实体类:

@Entity 
@Getter 
@Setter 
@AllArgsConstructor 
@NoArgsConstructor 
@ToString 
@Table(name = "Users", schema = "DevDatabase.dbo") 
public class MemberDetailsEntity 
{ 
    @Id 
    @NonNull 
    @Column(name = "Patient_Id") 
    private String PatientId;
    @Column(name = "PLN_ID")
    private String planId;
}

在迁移到Java 17后,我发现自动生成的查询在模式名称(DEVDATABASE.DBO)的开头和结尾添加了方括号,但它应该像这样添加:[DEVDATABASE].[DBO]或者不添加它们。因此,查询在MSSQL中执行失败,抛出以下错误:

ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Invalid object name DevDatabase.dbo.Users

org.springframework.dao.InvalidDataAccessResourceUsageException: JDBC exception executing SQL DevDatabase.dbo.Users

如何解决这个问题?

我尝试升级和降级Hibernate版本,但没有帮助。
所有建议的注解添加都已经完成,但问题仍未解决。

英文:

Below is the :

JPA Query generated at runtime: select m1_0.Patient_Id,m1_0.PLN_ID from [DevDatabase.dbo].Users m1_0 where m1_0.Patient_Id=?

ENTITY class:

@Entity 
@Getter 
@Setter 
@AllArgsConstructor 
@NoArgsConstructor 
@ToString 
@Table(name = "Users", schema = "DevDatabase.dbo") 
public class MemberDetailsEntity 
{ 
    @Id 
    @NonNull 
    @Column(name = "Patient_Id") 
    private String PatientId;
    @Column(name = "PLN_ID")
    private String planId;
}

After migrating to java 17, I see that the autogenerated query happens to add square brackets to the schema name (DEVDATABASE.DBO) at the beginning and the end, but it should either add like this
[DEVDATABASE].[DBO] or not add them. Because of it, the query fails to execute in mssql ad it throws

ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Invalid object name DevDatabase.dbo.Users
or
org.springframework.dao.InvalidDataAccessResourceUsageException: JDBC exception executing SQL DevDatabase.dbo.Users

How can this issue be resolved ?

I tried upgrading and downgrading the hibernate version. But nothing helped.
All recommended annotations additions to the entity class is already done yet not resolved.

答案1

得分: 0

@Table(name = "Users", catalog = "DevDatabase", schema = "dbo")
英文:

Perhaps you meant to write:

@Table(name = "Users", catalog = "DevDatabase", schema = "dbo") 

huangapple
  • 本文由 发表于 2023年5月14日 17:35:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76246769.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定