DB として sqlserver 2008 を使用して jboss 4.2.3 から 7.1.1 にアプリケーションを移植しようとしていますが、persistence.xml で方言を org.hibernate.dialect.SQLServerDialect から 2008 方言に変更したときに問題に直面しています。以前のバージョンの方言では、方言の変更が解決策として提供されたページネーションの問題に直面していました。私が分析したログから、いくつかの追加ステートメントが自動的に追加されていることがわかりました。
バージョンの詳細は以下に記載されています
16:46:10,844 INFO [org.hibernate.annotations.common.Version] (MSC service thread 1-5) HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
16:46:10,849 INFO [org.hibernate.Version] (MSC service thread 1-5) HHH000412: Hibernate Core {4.0.1.Final}
16:46:11,870 INFO [org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator] (MSC service thread 1-5) HHH000130: Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
16:46:11,892 INFO [org.hibernate.dialect.Dialect] (MSC service thread 1-5) HHH000400: Using dialect: org.hibernate.dialect.SQLServer2008Dialect
16:46:11,905 INFO [org.hibernate.engine.transaction.internal.TransactionFactoryInitiator] (MSC service thread 1-5) HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory
16:46:11,908 INFO [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (MSC service thread 1-5) HHH000397: Using ASTQueryTranslatorFactory
16:46:11,934 INFO [org.hibernate.validator.util.Version] (MSC service thread 1-5) Hibernate Validator 4.2.0.Final
実際のクエリは
select proj.proj_id,count(distinct projbid.user_id) as numRespondents,c.customer_name,proj.campaign_id from customer c,proj left join projbid ON (projbid.proj_id = proj.proj_id AND projbid.bid_status in (2, 5)) where proj.spec_id=spec.spec_id and proj.userid= :userId and proj.int_client_id=c.customer_id and proj.proj_state= :projState group by proj.proj_id, c.customer_name,proj.campaign_id order by proj.job_id ASC
JPA/Hibernate で使用されるクエリは次のとおりです。
16:47:39,206 INFO [stdout] (http-localhost-127.0.0.1-8080-2) Hibernate:
16:47:39,207 INFO [stdout] (http-localhost-127.0.0.1-8080-2) /* dynamic native SQL query */ WITH query AS (select
16:47:39,208 INFO [stdout] (http-localhost-127.0.0.1-8080-2) proj.proj_id,
16:47:39,213 INFO [stdout] (http-localhost-127.0.0.1-8080-2) count(bid.user_id) numrespondents,
16:47:39,214 INFO [stdout] (http-localhost-127.0.0.1-8080-2) c.customer_name,
16:47:39,215 INFO [stdout] (http-localhost-127.0.0.1-8080-2) proj.campaign_id,
16:47:39,216 INFO [stdout] (http-localhost-127.0.0.1-8080-2) ROW_NUMBER() OVER (
16:47:39,217 INFO [stdout] (http-localhost-127.0.0.1-8080-2) order by
16:47:39,218 INFO [stdout] (http-localhost-127.0.0.1-8080-2) proj.proj_id asc) as __hibernate_row_nr__
16:47:39,219 INFO [stdout] (http-localhost-127.0.0.1-8080-2) from
16:47:39,221 INFO [stdout] (http-localhost-127.0.0.1-8080-2) customer c,
16:47:39,222 INFO [stdout] (http-localhost-127.0.0.1-8080-2) proj
16:47:39,223 INFO [stdout] (http-localhost-127.0.0.1-8080-2) left join
16:47:39,223 INFO [stdout] (http-localhost-127.0.0.1-8080-2) projbid
16:47:39,224 INFO [stdout] (http-localhost-127.0.0.1-8080-2) on (projbid.proj_id = proj.proj_id
16:47:39,225 INFO [stdout] (http-localhost-127.0.0.1-8080-2) and projbid.bid_status in (2,
16:47:39,225 INFO [stdout] (http-localhost-127.0.0.1-8080-2) 5))
16:47:39,226 INFO [stdout] (http-localhost-127.0.0.1-8080-2) where
16:47:39,227 INFO [stdout] (http-localhost-127.0.0.1-8080-2) proj.spec_id=proj.spec_id
16:47:39,227 INFO [stdout] (http-localhost-127.0.0.1-8080-2) and
16:47:39,228 INFO [stdout] (http-localhost-127.0.0.1-8080-2) and proj.userid= ?
16:47:39,229 INFO [stdout] (http-localhost-127.0.0.1-8080-2) and proj.int_client_id=c.customer_id
16:47:39,230 INFO [stdout] (http-localhost-127.0.0.1-8080-2) and proj.proj_state= ?
16:47:39,231 INFO [stdout] (http-localhost-127.0.0.1-8080-2) group by
16:47:39,231 INFO [stdout] (http-localhost-127.0.0.1-8080-2) proj.proj_id,
16:47:39,234 INFO [stdout] (http-localhost-127.0.0.1-8080-2) job.userid,
16:47:39,236 INFO [stdout] (http-localhost-127.0.0.1-8080-2) c.customer_name,
16:47:39,237 INFO [stdout] (http-localhost-127.0.0.1-8080-2) proj.campaign_id
*16:47:39,238 INFO [stdout] (http-localhost-127.0.0.1-8080-2) group by
16:47:39,239 INFO [stdout] (http-localhost-127.0.0.1-8080-2) proj.proj_id,
16:47:39,243 INFO [stdout] (http-localhost-127.0.0.1-8080-2) count(projbid.user_id) numrespondents,
16:47:39,244 INFO [stdout] (http-localhost-127.0.0.1-8080-2) c.customer_name,
16:47:39,245 INFO [stdout] (http-localhost-127.0.0.1-8080-2) proj.campaign_id )* SELECT
16:47:39,246 INFO [stdout] (http-localhost-127.0.0.1-8080-2) *
16:47:39,246 INFO [stdout] (http-localhost-127.0.0.1-8080-2) FROM
16:47:39,247 INFO [stdout] (http-localhost-127.0.0.1-8080-2) query
16:47:39,248 INFO [stdout] (http-localhost-127.0.0.1-8080-2) WHERE
16:47:39,248 INFO [stdout] (http-localhost-127.0.0.1-8080-2) __hibernate_row_nr__ >= ?
16:47:39,249 INFO [stdout] (http-localhost-127.0.0.1-8080-2) AND __hibernate_row_nr__ < ?
**I am getting the exception as below**
16:47:39,262 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http-localhost-127.0.0.1-8080-2) SQL Error: 156, SQLState: S0001
16:47:39,264 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http-localhost-127.0.0.1-8080-2) Incorrect syntax near the keyword 'group'.
groupby が複数回追加されていることがわかります。実行される Java スニペットは以下のとおりです。
results = em.createNativeQuery(selectSql.toString()).setParameter("userId", userId).setParameter("projState", 2).setMaxResults(param.getPageSize()).setFirstResult(param.getStart()).setHint("org.hibernate.readOnly", true).getResultList();
どんな助けでも大歓迎です。