【发布时间】:2016-10-25 16:03:56
【问题描述】:
我的所有表都在 SQLServer 数据库中的相同架构中,因此我宁愿不必在每个 @Table 注释中指定架构。我已将架构名称放在我的连接字符串中:
spring.datasource.url=jdbc:sqlserver://localhost;instanceName=SQLEXPRESS;databaseSchema=TST;databaseName=TestDB;integratedSecurity=true;
当我的注释是@Table(name="MY_TABLE"),并且Hibernate 尝试插入时,我收到Invalid object name 'MY_TABLE'. 错误消息。
如果注释是@Table(name="MY_TABLE", schema="TST"),则插入按预期工作。
SQLServer 方言不支持连接字符串中的架构吗?
这里是所有 Spring/Hibernate 属性:
spring.datasource.url=jdbc:sqlserver://localhost;instanceName=SQLEXPRESS;databaseSchema=EXP;databaseName=YRC_PILOT2;integratedSecurity=true;
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.database-platform = org.hibernate.dialect.SQLServerDialect
spring.jpa.show-sql=true
如果我必须为每个表指定架构,那就这样吧。但如果我想切换模式名称,这似乎有点笨拙。
【问题讨论】:
-
SQL Server 不支持在连接字符串中设置架构。您要么必须继续做你正在做的事情,要么为应用程序的 SQL 帐户设置默认架构。见stackoverflow.com/q/3282665/1324345
-
persistence.xml 允许你指定它!
标签: sql-server spring hibernate jpa