天天看點

Spring Hibernate開發點滴

在做開發過程中總會遇上些無厘頭的錯誤,收集了些開發點滴,希望後來者不會踩上同一個陷阱,

1.Q:An error occured in the bean. Error Message is: Failed to lazily initialize a collection - no session or session was closed

A:未初始化加載

2. Q:org.springframework.beans.factory.BeanDefinitionStoreException: Error registering bean with name '' defined in resource [/WEB-INF/applicationContext-PoService.xml] of ServletContext: Bean class [com.itorgan.lherp.dao.impl.PoReceiveDAOImpl] not found; nested exception is java.lang.ClassNotFoundException: com.itorgan.lherp.dao.impl.PoReceiveDAOImpl

A:重新開機TOMCAT

3. Q:An error occured in the bean. Error Message is: An error occurred while evaluating custom action attribute "value" with value "${poItem.poItemNo}": Unable to find a value for "poItemNo" in object of class "com.itorgan.lherp.vo.PoReceiveItem" using operator "." (null)

A:變量${poItem.poItemNo}與VO com.itorgan.lherp.vo.PoReceiveItem 無法綁定

4. Q:org.springframework.dao.DataIntegrityViolationException: Hibernate operation: ORA-02291: integrity constraint (LH.FK_PO_RECEIVE_CUSTOMER_NO) violated - parent key not found

; nested exception is java.sql.BatchUpdateException: ORA-02291: integrity constraint (LH.FK_PO_RECEIVE_CUSTOMER_NO) violated - parent key not found

A:有對象未綁定

5. Q:vo配置檔案解釋

A:*大寫的部分inverse="true"表示 ParentPO 本身不維護表之間的關系!,而由想反的一方 children來維護,

*CASCADE=“ALL”表示 無論是update,insert ,delete 都保持幾連關系

*lazy="true"表示初始化父親的時候不會把所有的兒子都從資料庫中load進來。

6. Q:org.springframework.jdbc.BadSqlGrammarException: Bad SQL grammar [] in task 'Hibernate operation'; nested exception is java.sql.SQLException: ORA-02289: sequence does not exist

A:VO中的sequence寫錯

7. Q:java.lang.ClassCastException: [Ljava.lang.String;

A:類型轉換錯誤,資料庫是否有重複記錄