hibernate錯誤筆記
···在hibernate項目中插入數據時候出現錯誤
1、Could not execute JDBC batch update
2、ORA-00001: unique constraint (SCOTT.PK_ID) violated
解決方案以及出現問題的地方 :
1、是因為數據庫的主鍵不許加入相同數據 唯一性的約束
···在hibernate項目中插入數據時候出現錯誤(表中建立序列) 當插入數據太長或者序列設置有問題發生沖突產生以下錯誤
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not get next sequence value
和
Caused by: java.sql.SQLException: ORA-08004: sequence HTH.NEXTVAL exceeds MAXVALUE and cannot be instantiated
解決方案 :編輯修改表的序列 修改添加的數據
···在hibernate項目中
2009-9-15 8:52:56 org.hibernate.util.JDBCExceptionReporter logExceptions
嚴重: ORA-02289: sequence does not exist
解決方案
問題存在 custmer.hbm.xml
<id name="id" column="CID">
<generator class="native" />
</id>
應該改成:
<id name="id" column="CID">
<generator class="sequence">
<param name="sequence">SEQ_hibernate</param>
</generator>
<id>
通過配置文件指出你所使用的Sequence,SEQ_hibernate是在oracle中已經創建好的。調試OK!
注意 :
在hibernate項目中字段不為空的情況下 除了設置數據庫外在 映射文件里也需要設設置
<property name="listedDate" type="date">
<column name="LISTED_DATE" length="10" not-null="false" />
</property>
not-null="false" 也需要設置
···一對一關系在hibernate中出現以下錯誤(標注模式)
An AnnotationConfiguration instance is required to use <mapping class="com.anbo.mapping.Ulogin"/>
在外鍵的實體類中加
@GenericGenerator(name = "generator", strategy = "foreign", parameters = @Parameter(name = "property", value = "ulogin"))
@Id
@GeneratedValue(generator = "generator")
因為在主鍵的實體類文件中有
@OneToOne(fetch = FetchType.LAZY, mappedBy = "ulogin", cascade=CascadeType.ALL)
而在外鍵的實體類中并沒有指明對應關系