【发布时间】:2016-06-12 16:30:55
【问题描述】:
我在我的项目中为 CRUD 层和 ORM 使用由 hibernate 支持的 spring 数据。我首先使用H2。但是在切换到 SQL Server 2014 时,我遇到了以下问题: 我使用以下服务:
@Query("Select example from Example example where
example.exampleProperty like CONCAT('%',:param,'%')")
List<Example> findByProductLibe(@Param("param") String param);
使用属性获取示例对象(来自示例表)。它在 H2 中运行良好,但移动到 sql server(通过将配置通道和方言切换到 sql server)由于 Hibernate 生成的查询如下所示,我有一个 BadSqlGrammarException:
Hibernate:
select
ex.param1 as param1,
ex.param2 as param2
from
example ex
where
example.exampleProperty like ('%'||?||'%')
问题在于“|”字符,它会打印 'Incorrect syntax near '|' '
这是我的数据库配置:
database.driver = com.microsoft.sqlserver.jdbc.SQLServerDriver
database.password =
database.username =
hibernate.dialect = org.hibernate.dialect.SQLServerDialect
hibernate.ejb.naming_strategy = org.hibernate.cfg.ImprovedNamingStrategy
hibernate.hbm2ddl.auto = create
hibernate.generate_statistics = true
hibernate.format_sql = true
hibernate.show_sql = true
感谢任何帮助或指示。
【问题讨论】:
-
请添加您的 Hibernate 配置。
标签: sql-server hibernate spring-data