-1
我已经看到类似的问题,但在我的情况下,它不起作用。 我需要获取序列的下一个值。在postgreSQL中使用jpa存储库从序列获取下一个值
模型类:
@Entity
@Table(name = "item")
public class Item {
@Id
@SequenceGenerator(name = "id_seq", sequenceName = "item_id_seq", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "id_seq")
@Column(name = "id", updatable = false)
protected Long id;
}
JPA库:
public interface ItemRepository extends JpaRepository<Item, Long> {
List<Item> findFirst10ByOrderByPublicationDateDesc();
@Query(value = "SELECT item_id_seq.nextval FROM item", nativeQuery =
true)
Long getNextSeriesId();
}
我希望得到任何帮助。