我看到了类似的问题,但在我的情况下它不起作用。我需要获取序列的下一个值。
模型类:
@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 Repository:
public interface ItemRepository extends JpaRepository<Item, Long> {
List<Item> findFirst10ByOrderByPublicationDateDesc();
@Query(value = "SELECT item_id_seq.nextval FROM item", nativeQuery =
true)
Long getNextSeriesId();
}
我会感激任何帮助。