我的梦想 我的JAVA

I am who i am

 

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)
而在外键的实体类中并没有指明对应关系


 

posted on 2011-10-27 22:43 木子伟 阅读(359) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

导航

统计

常用链接

留言簿

随笔档案

文章档案

搜索

最新评论