I need have a need to return nextVal at various times in my application. I have an entity class like the following:
@Entity
@Table(name = "TBL_CACL")
public class Cacl {
@Id
@SequenceGenerator(name = "caclGenerator", sequenceName = "caclSeq", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "calcGenerator")
@Column(name = "ID")
private Integer id;
// more stuff below....
, and I added the following in my repository interface:
@Repository
public interface CaclRepository extends JpaRepository<Cacl, Integer> {
@Query(value = "SELECT caclSeq.nextval FROM Cacl", nativeQuery = true)
Long getNextSeriesId();
However when I attempt to read it like this:
long nextval = caclRepository.getNextSeriesId() + 1;
, I get this exception:
(can't show entire stack trace)
org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
Caused by: org.postgresql.util.PSQLException: ERROR: relation "cacl" does not exist
Its puzzling to me that I am getting error "cacl does not exist" because this application has been up and working for some time. All that I have done is add the @SequenceGenerator, updated the @GeneratorValue to link to the @SequenceGenerator annotation, and create the new query. I would be grateful for any ideas as to what I am doing wrong. thanks
caclSeq?