JPA、SQL Server - 带前缀和序列的列

JPA, SQL Server - column with prefix and sequence

提问人:KaTevIet 提问时间:2/15/2023 最后编辑:Dale KKaTevIet 更新时间:2/15/2023 访问量:84

问:

使用 JPA 和 SQL Server 创建带有前缀和序列的列。

我需要一些带有前缀和序列的列(不是主键),例如 T1、T2、T3。

我试过了这个:

CREATE SEQUENCE t_sequence START WITH 1 INCREMENT BY 1;
ALTER TABLE gate ADD T_NUM INT;
ALTER TABLE gate ADD T VARCHAR(30);
...
    @Column(name = "T_NUM")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "t_sequence ")
    @SequenceGenerator(name = "t_sequence ", t_sequence = "mir_sequence", allocationSize = 1, initialValue = 1)
    private int tNum;

    @Column(name = "T")
    private String t;
...
    @PrePersist
    public void onCreate() {
        super.onCreate();
        t= "T" + this.tNum;
    }

因此,我总是在 t 列中有 T0。

sql-server JPA 序列

评论


答: 暂无答案