我正在爲我的CRUD圖層和ORM項目使用由hibernate支持的彈簧數據。我首先使用H2。但是切換到SQL Server 2014的時候,我遇到了以下問題:使用屬性帶休眠功能的SQL Server方言
@Query("Select example from Example example where
example.exampleProperty like CONCAT('%',:param,'%')")
List<Example> findByProductLibe(@Param("param") String param);
得到實施例的對象(例如從表): 我用下面的服務。它在H2運作良好,但移動到SQL服務器(通過切換配置信道和方言到SQL Server)我有一個BadSqlGrammarException由於由Hibernate生成的查詢如下:
Hibernate:
select
ex.param1 as param1,
ex.param2 as param2
from
example ex
where
example.exampleProperty like ('%'||?||'%')
的問題是與'|'字符,它會打印'語法不正確'|' 「
這裏是我的數據庫配置:
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配置。 –