spring-projects / spring-projects/spring-data-rest

How to use projections with pagination and sorting..? [DATAREST-1315]

Open
#1,675 1 comment 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

type: bug
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

AnilkumarReddy opened DATAREST-1315 and commented

@Entity@Entitypublic class Emp {
@Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id;
@Column private String name;
@Column private Double salary;
@Column private String address;
@ManyToMany(mappedBy = "emps", fetch = FetchType.EAGER) private List<Account> accounts;

}

 

 

@Entity@Entitypublic class Account { @Id @GeneratedValue(strategy = GenerationType.AUTO) private long id;
@Column(nullable = false) private String name;
@ManyToMany(cascade = CascadeType.ALL) @JoinTable(name = "emp_acc", joinColumns = @JoinColumn(name = "acc_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "emp_id", referencedColumnName = "id")) private List<Emp> emps;

}

 

 

@Projection(name = "EmpView", types = { Emp.class })@Projection(name = "EmpView", types = { Emp.class })public interface EmpView {
@Value("#{target.id}") Long getId();
String getAddress();
List<Account> getAccounts();
}

 

 

@RepositoryRestResource(excerptProjection = EmpView.class)@RepositoryRestResource(excerptProjection = EmpView.class)public interface EmpRepo extends JpaRepository<Emp, Long>, CrudRepository<Emp, Long>, JpaSpecificationExecutor<Emp> {
@Query("select e.id as id, e.address as address, e.accounts as accounts from Emp as e") Page<EmpView> findAll1(Pageable pageable);
}

 

 

 

Getting the below issue


{
"timestamp": 1544023971460,
"status": 500,
"error": "Internal Server Error",
"exception": "org.springframework.dao.InvalidDataAccessResourceUsageException",
"message": "could not prepare statement; SQL [select emp0_.id as col_0_0_, emp0_.address as col_1_0_, . as col_2_0_, account2_.id as id1_0_, account2_.name as name2_0_ from emp emp0_ inner join emp_acc accounts1_ on emp0_.id=accounts1_.emp_id inner join account account2_ on accounts1_.acc_id=account2_.id order by emp0_.address asc limit ?]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement",
"path": "/emps/with"
}


Attachments:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.