Skip to content

Latest commit

 

History

History
51 lines (41 loc) · 1.04 KB

File metadata and controls

51 lines (41 loc) · 1.04 KB

Spring Data JPA

Search All Data Object

List<?> findAll();

Search by Pagination

Page<?> findAll(Pageable pageable)

Search By Name [=/equal]

Page<?> findByName(Pageable pageable);

Search Like & Not Case Sensitive

Page<?> findByNameContainsIgnoreCase(String name, Pageable pageable);

Multiple Parameter Search

Page<?> findAllByNameContainsIgnoreCaseAndProvince(String name, Province province, Pageable pageable);

Working on Sequence [postgresql]


/* Entity Class */
@Data
@Entity
@Table(name = "my_sequence")
public class MySequence {
    @Id
    @SequenceGenerator(name = "id_seq", sequenceName = "mq_id_seq", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "id_seq")
    private Long id;
}

/* Repository */
public interface MySequenceRepo extends JpaRepository<MySequence, Long>  {
    @Query(value = "SELECT nextval('mq_id_seq')", nativeQuery = true)
    Long getNextSeriesId();
}

/* Sample Code */
Long seq = this.mySequenceRepo.getNextSeriesId();