Я не могу создать список счетов, отсортированный по рейтингу для конкретного пользователя. Даже если рейтинга нет, счет-фактура должен быть указан (пользователь — это всего лишь параметр для фильтрации рейтинга)
Код: Выделить всё
{
invoiceA :
rating:2
others fields
invoiceB :
rating:3
others fields
invoiceC :
others fields
}
Код: Выделить всё
@Entity
public class Invoice {
@OneToMany(mappedBy = "invoice", fetch = FetchType.LAZY)
Set ratings;
}
@Entity
public class InvoiceRating {
@EmbeddedId
BusinessTransactionRating ratingKey;
@ManyToOne
@MapsId("userId")
@JoinColumn(name = "user_id")
User user;
@ManyToOne
@MapsId("transactionId")
@JoinColumn(name = "invoice_id")
Invoice invoice;
int rating;
}
@Embeddable
public class BusinessTransactionRating {
@Column(name = "transaction_id")
Long transactionId;
@Column(name = "user_id")
Long userId;
}
@Entity
public class User {
}
Код: Выделить всё
CriteriaQuery criteriaQuery = cBuilder.createQuery(Invoice.class);
Root rootInvoice = criteriaQuery.from(Invoice.class);
pageable.getSort().stream().forEach(order -> { // sorting
Path prop = rootInvoice.get(order.getProperty());
list.add(order.isAscending() ? cBuilder.asc(prop) : cBuilder.desc(prop));
// finalQuery.orderBy();
});
CriteriaQuery criteriaQueryOrder = finalQuery.orderBy(list);
// TO DO / Add the count Line and the rebuild pageImpl
TypedQuery queryPaginate = entityManager.createQuery(criteriaQueryOrder);
Подробнее здесь: https://stackoverflow.com/questions/790 ... onstraints