Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在postgreSQL中使用jpa存储库从序列中获取下一个值_Java_Postgresql_Jpa_Spring Data Jpa_Spring Data - Fatal编程技术网

Java 在postgreSQL中使用jpa存储库从序列中获取下一个值

Java 在postgreSQL中使用jpa存储库从序列中获取下一个值,java,postgresql,jpa,spring-data-jpa,spring-data,Java,Postgresql,Jpa,Spring Data Jpa,Spring Data,我见过类似的问题,但在我的情况下,它不起作用。 我需要得到序列的下一个值 模型类: @Entity @Table(name = "item") public class Item { @Id @SequenceGenerator(name = "id_seq", sequenceName = "item_id_seq", allocationSize = 1) @GeneratedValue(strategy = GenerationType.SEQUENCE, gene

我见过类似的问题,但在我的情况下,它不起作用。 我需要得到序列的下一个值

模型类:

@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();
}
public interface ItemRepository扩展了JpaRepository{
按OrderByPublicationDateDesc()列出FindFirst10;
@查询(value=“SELECT item\u id\u seq.nextval FROM item”,nativeQuery=
(对)
Long getNextSeriesId();
}
非常感谢您的帮助。

我找到了解决方案:

@Query(value = "SELECT nextval('item_id_seq')", nativeQuery =
            true)
    Long getNextSeriesId();
我的错误是我使用了oracle语法,而不是我正在使用的postgreSQL