Topic: hibernate + oracle 映射主键问题 |
Print this page |
1.hibernate + oracle 映射主键问题 | Copy to clipboard |
Posted by: ybbkd2 Posted on: 2005-07-16 11:23 我先设置主键class_ID 为 <generator class="native"/>: cls.setClassName("专访"); cls.setClassNotes("专访专用栏目"); cls.setClassIntr("打造企业,诉说故事"); 保存时错误提示: Hibernate: select hibernate_sequence.nextval from dual net.sf.hibernate.exception.GenericJDBCException: Could not save object Caused by: java.sql.SQLException: ORA-02289: 序列(号)不存在 我想使用 触发器+sequence 数据库自动维护ID号生成,不需要程序干预,如何做 ? 希望能找到答案!! 附: /* -------------- oracle sp.sql begin -------------------------*/ Create table btcn_news_class ( class_id Integer Default 0 NOT NULL , class_name Varchar2(10) Default '' NOT NULL , class_intr Clob Default '' NOT NULL , class_notes Varchar2(4000) Default '' NOT NULL , parent Integer Default 0 NOT NULL ) / Alter table btcn_news_class add Constraint pk_btcn_news_class primary key (class_id) / create sequence news_class_id minvalue 1 maxvalue 999999999999999999999999999 start with 1 increment by 1 cache 20 order; /* Trigger for sequence news_class_id for table btcn_news_class attribute class_id */ Create or replace trigger t_news_class_id before insert on btcn_news_class for each row begin SELECT news_class_id.nextval INTO :new.class_id FROM dual; end; / /* ---------- sp.sql end. -------------- */ 下面是hbm.xml 对主键的映射(myeclipse 生成的): <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" > <hibernate-mapping package="cn.zhongcheng.news"> <class name="BtcnNewsClass" table="BTCN_NEWS_CLASS"> <id name="classId" column="CLASS_ID" type="java.lang.Long"> <generator class="native"/> </id> <property name="className" column="CLASS_NAME" type="java.lang.String" not-null="true" /> <property name="classIntr" column="CLASS_INTR" type="java.lang.String" not-null="true" /> <property name="classNotes" column="CLASS_NOTES" type="java.lang.String" not-null="true" /> <property name="parent" column="PARENT" type="java.lang.Long" not-null="true" /> </class> </hibernate-mapping> <!------------------------- end ------------------------> |
2.Re:hibernate + oracle 映射主键问题 [Re: ybbkd2] | Copy to clipboard |
Posted by: youlq Posted on: 2005-07-18 08:50 old:
new:
note:SEQ_CLASS_ID is the name of your sequence |
3.Re:hibernate + oracle 映射主键问题 [Re: ybbkd2] | Copy to clipboard |
Posted by: ybbkd2 Posted on: 2005-09-08 17:23 3x!!! 解决了 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |