jpanamed-queryhibernate-native-query

how to call spring jap query none parameters


I use spring data jpa with native query

I have already some query like this

How to use native query none parameter.

String q="SELECT t1.blockNumber-1 FROM someTAble t1 LEFT JOIN  someTAble t2 ON t2.blockNumber = t1.blockNumber-1 WHERE t2.blockNumber IS NULL AND t1.blockNumber> 0 ORDER BY t1.blockNumber";

@Query(value = q,nativeQuery = true)
List<Entity> findByBlockNumberIs();

they are occur errors Column 'sequence' not found.

That query means are when i insert some Contiguous data int value then i find missing data.

But this query working

SELECT *,t1.blockNumber-1 FROM someTAble t1 LEFT JOIN  someTAble t2 ON t2.blockNumber = t1.blockNumber-1 WHERE t2.blockNumber IS NULL AND t1.blockNumber> 0 ORDER BY t1.blockNumber

The difference between the two queries is whether there is a '*' or not

how to change simple to my query.

How to i changed error

OR How to use spring data jpa predicate

  QEntity qBe1=  QEntity .blockEntity;
         QEntity qBe2=  QEntity .blockEntity;


        build.and(qBe2.blockNumber.eq(be.getBlockNumber()-1))

                .and(qBe2.blockNumber.isNull().and(qBe1.blockNumber.gt(0)));

is predicate can use left join?


Solution

  • well...

    use this.

    List<Integer> findByBlockNumber()