2017-05-25 68 views
1

我用三個左外連接編寫了一個SQL服務器查詢,它在SQL SERVER控制檯中執行得很好。ms sql server數據庫中不能綁定多部分標識符

下面是該查詢

select [a].[audittraceid], 
[a].[description], 
[a].[remarks], 
[a].[ip], 
[a].[oldvalue], 
[a].[newvalue], 
[a].[lastupdateduser], 
convert(varchar(19),[a].[lastupdatedtime],120) as lastupdatedtime, 
convert(varchar(19),[a].[createdtime],120) as createdtime, 
[a].[affectedkey], 
[ur].[userrolecode] as userrolecode, 
[ur].[description] as userroledes, 
[p].[pagecode] as pagecode, 
[p].[description] as pagedes, 
[t].[description] as taskdes 
From [TESTDB].[dbo].[Audittrace] [a] 
left outer join [TESTDB].[dbo].[Userrole] [ur] on [a].[userrolecode]=[ur].[userrolecode] 
left outer join [TESTDB].[dbo].[Page] [p] on [a].[pagecode]=[p].[pagecode] 
left outer join [TESTDB].[dbo].[Task] [t] on [a].[taskcode]=[t].[taskcode] 
order by [a].[lastupdatedtime] desc 

但是,當我用我的申請此查詢它使用休眠,休眠改變,因爲下面的查詢。

WITH query AS (
    SELECT inner_query.*, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( 
     select TOP(10) [a].[audittraceid] as page0_, 
     [a].[description] as page1_, 
     [a].[remarks] as page2_, 
     [a].[ip] as page3_, 
     [a].[oldvalue] as page4_, 
     [a].[newvalue] as page5_, 
     [a].[lastupdateduser] as page6_, 
     convert(varchar(19),[a].[lastupdatedtime],120) as lastupdatedtime, 
     convert(varchar(19),[a].[createdtime],120) as createdtime, 
     [a].[affectedkey] as page7_, [ur].[userrolecode] as userrolecode, 
     [ur].[description] as userroledes, [p].[pagecode] as pagecode, 
     [p].[description] as pagedes, 
     [t].[description] as taskdes From [BIMPUTHDEV01].[dbo].[Audittrace] [a] 
     left outer join [TESTDB].[dbo].[Userrole] [ur] on [a].[userrolecode]=[ur].[userrolecode] 
     left outer join [TESTDB].[dbo].[Page] [p] on [a].[pagecode]=[p].[pagecode] 
     left outer join [TESTDB].[dbo].[Task] [t] on [a].[taskcode]=[t].[taskcode] 
     order by [a].[lastupdatedtime] desc 
    ) inner_query 
) 
SELECT 
page0_, 
page1_, 
page2_, 
page3_, 
page4_, 
page5_, 
page6_, 
lastupdatedtime, 
createdtime, 
page7_, 
userrolecode, 
userroledes, 
pagecode, 
[p].[description] as pagedes, /*This line gives the error*/ 
[t].[description] as taskdes 
FROM query 

在這種改變的Hibernate查詢給運行應用程序時我下面的錯誤。

  • 無法綁定多部分標識符「p.description」。
  • org.hibernate.exception.SQLGrammarException:多部分 標識符「p.description」無法綁定。

  • 引起:com.microsoft.sqlserver.jdbc.SQLServerException: 多部分標識符「p.description」無法綁定。

我在堆棧溢出中發現了相同類型的問題,但沒有找到任何問題的正確答案。

任何人都可以描述爲什麼會發生這種情況,如何解決這個問題將是非常有益的。提前感謝。

回答

2

我找到了答案。

在我的Hibernate配置文件以前我下面添加休眠方言屬性。

<property name="hibernate.dialect">org.hibernate.dialect.SQLServer2008Dialect</property> 

但它是錯的。

我改變hibernate的方言屬性如下。

<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property> 

這工作正常。

謝謝。

相關問題