提问人:Adolis Pali 提问时间:11/1/2020 更新时间:8/25/2021 访问量:31
PostgresSQL JPA 自定义序列
PostgresSQL JPA custom sequence
问:
- 在postgres中,我创建序列:user_details_userid_seq
- 现在我想在我的课堂上使用它
public class UserDetails {
@Id
private int userId;
我想要 userId 将读取并生成下一个值 user_details_userid_seq(在 databas 中定义)。如何做到这一点?
答:
1赞
Adolis Pali
11/1/2020
#1
感谢 crizzis 提供关键字进行搜索,但解决方案:
@GeneratedValue(generator="my_seq_gen")
@SequenceGenerator(name="my_seq_gen", sequenceName="user_details_userid_seq", allocationSize = 1)
其中,参数将序列增量定义为 。allocationSize = 1
1
评论
@GeneratedValue(strategy = SEQUENCE, generator = "user_details_generator") @SequenceGenerator(name = "user_details_generator", sequenceName="user_details_userid_seq", allocationSize = <your_sequence_increment>)
allocationSize = 1