I request Order Index Pageable that contain sort condition example (id, desc)
request url
/orders?page=0&size=20&sort=id,desc
error message
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.hql.internal.ast.QuerySyntaxException: Invalid path: 'order.id' [select order1
from com.mystore.domain.Order order1
order by order.id desc]; nested exception is java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: Invalid path: 'order.id' [select order1
from com.mystore.domain.Order order1
order by order.id desc]] with root cause
org.hibernate.hql.internal.ast.QuerySyntaxException: Invalid path: 'order.id' [select order1
from com.mystore.domain.Order order1
I test change @Entity(name="otherOrder")
but not working
but another entity name pageable with sort working properly for example seller, account, product
orderClass
@Entity
@Table(name="orders")
data class Order(
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long = 0,
@Column(unique = true)
val merchantUid: String) {}
orderController
@GetMapping
@ApiPageable
fun index(searchOrder: SearchOrder, pageable: Pageable): Page<Any> {
return orderService.findAllWithSearchAndPageable(searchOrder, pageable)
}
orderService
fun findAllWithSearchAndPageable(searchOrder: SearchOrder, pageable: Pageable): Page<Any> {
return orderRepository.findAllWithSearchAndPageable(searchOrder, pageable)
}
orderRepositoryImpl
@Autowired
lateinit var jpaQueryFactory: JPAQueryFactory
fun findAllWithSearchAndPageable(serarchOrder: SearchOrder, pageable: Pageable): PageImpl<Any> {
val query = jpaQueryFactory.select(order)
.from(order)
val orders = querydsl!!.applyPagination(pageable, query).fetch()
return PageImpl(orders as List<Any>, pageable, query.fetchCount())
}
change Order -> OtherNameOther is one solution have the other solution?