1.hibernate + oracle 映射主键问题 Copy to clipboard Posted by: ybbkd2 Posted on: 2005-07-16 11:23 我先设置主键class_ID 为 : 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 生成的):
-------------------------------------------------------------------------------- 2.Re:hibernate + oracle 映射主键问题 [Re: ybbkd2] Copy to clipboard Posted by: youlq Posted on: 2005-07-18 08:50 old: new: SEQ_CLASS_ID note:SEQ_CLASS_ID is the name of your sequence