昨天出了一個奇怪的問題,hibernate通過實體Id(char(10)型)取得數據,session.find("from TableName where id=?","value");取不到數據,但數據庫里是有這個條數據。真奇怪,后來用pl/sql看數據庫,鼠標點到Id那時,可以看到內容后面還有一些空格,帶著期望與質疑把字段里的值自制過來, session.find("from TableName where id=?","value ");后發現可以。我特別試了下connection.createStatement("select * from table_name where id='value'");則正常取數據,session.find("from TableName where id=?","value");而卻找不到數據,然后又試了下
ptmt = connection.prepareStatement(select * from table_name where id=?");
ptmt.setString(1,"year");
這樣也不行,以是結論是:jdbc驅動PrepareStatement對char字段類型的查找問題,因為hibernate是用PrepareStatement的,自然,hibernate對char對應的屬性條件查找出現找不到的情況,
解決辦法是:
1.屬性用TRIM函數處理:session.find("from TableName where TRIM(id)=?","value");
2.char改為varchar2類型
今天試了下mysql,它不會這樣的情況,所以結論是:Oracle JDBC PreparedStatement的bug(有可能它故意這樣)
posted on 2007-10-17 22:22
流浪汗 閱讀(5565)
評論(1) 編輯 收藏 所屬分類:
oracle