在Oracle中建立sequence,名称为pk:
create sequence pk
    start with 1
    increment by 1
    maxvalue 2000
    nocycle
    cache 30;
在映射文件中修改:

<class name="com.kay.pojo.Student" table="STUDENT" schema="KAY">
        <id name="id" type="java.lang.Long">
            <column name="ID" precision="22" scale="0" />
            <generator class="sequence">
             <param name="sequence">pk</param>//pk为sequence名称
            </generator>
        </id>
        <property name="name" type="java.lang.String">
            <column name="NAME" length="50" />
        </property>
    </class>


测试代码:
@Test
 public void testAdd() {
  
  Student stu = new Student();
  stu.setName("Bill");
  boolean flag = dao.add(stu);
  assertEquals(true, flag);
 }

控制台输出:
Hibernate: select pk.nextval from dual
Hibernate: insert into KAY.STUDENT (NAME, ID) values (?, ?)

相关文章:

  • 2021-09-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-10
  • 2022-12-23
  • 2021-09-11
  • 2021-07-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-17
  • 2022-12-23
  • 2021-09-21
  • 2021-10-16
相关资源
相似解决方案