为什么序列标识不能在SQL服务器序列中工作?

时间:2016-07-27 12:53:52

标签: sql-server hibernate sequence hibernate-mapping

为什么序列标识在SQL服务器序列中不起作用?

@GenericGenerator( name = "sequence",
            strategy = "sequence-identity",
            parameters = {
                    @org.hibernate.annotations.Parameter(
                            name = "sequence",
                            value = "SEQ_PARTNER_TIMETABLE_ID"
                    )

        })

1 个答案:

答案 0 :(得分:0)

试试这个:

在SQL Server中创建一个序列

CREATE SEQUENCE [schema_name . ]sequence_name   
     START WITH 1
     INCREMENT BY 1
     NO CYCLE
    ; 

然后在您实体的ID

中调用此序列
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "users_seq_gen")
@SequenceGenerator(name = "users_seq_gen", sequenceName = "sequence_name")