简体   繁体   中英

Why does my update query that works in SQL Server 2005 Management Studio not work as a Prepared Query in Java?

I have a Table [Name Table] and an associated table workSchedule . I'm using Hibernate 3.6.7.Final to generate my query. The result is:

update Personnel.dbo.[Name Table] set workSchedule=? where [Name IRC]=?

Which throws an Exception:

11-22@10:30:41 WARN [] JDBCExceptionReporter - SQL Error: 8624, SQLState: S0001
11-22@10:30:41 ERROR [] JDBCExceptionReporter - Internal Query Processor Error: The query processor could not produce a query plan. For more information, contact Customer Support Services.

[Name Table].workSchedule is a foreign key defined thus:

ALTER TABLE [Name Table] ADD workSchedule VARCHAR(34) 
            FOREIGN KEY REFERENCES workSchedule(id);  

workSchedule.id is defined like this:

CREATE TABLE workSchedule
( /* format = letter-days-lunch EX: A-5-1 */   
  id AS CASE lunch
         WHEN 1 THEN scheduleLetter+'-'+CONVERT(VARCHAR, scheduleDays)+'-'+'1'
         ELSE scheduleLetter+'-'+CONVERT(VARCHAR, scheduleDays)+'-'+'5'
        END PERSISTED NOT NULL,
/* rest of table follows */
);

If I copy paste the above update query into SSMS and plug values directly in for the ?s it works.

UPDATE:
I just tried changing out the PRIMARY KEY of the table WorkSchedule for an INT IDENTITY column. I left renamed id to shift and otherwise left it as column on the table. I also updated both POJO's and .hbm.xml files. The update query still fails, with the same exception.

I'm listing this as an answer because it's what I ended up doing to solve my problem.

I completely removed the calculated field on WorkSchedule.
I implemented the calcualations as a getter in the the POJO instead.
Re-tooled workschedule to use an IDENTITY for the PK
and re-linked [Name Table] to the new IDENTITY field instead. now it all works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM