QueryDSL: Pagination with Order By on composite key not possible #1990
-
Entities@Entity
public class MessageBundle {
@EmbeddedId
private MessageBundleIdEmbeddable id;
@Column(name = "VALUE", columnDefinition = "VARCHAR(1024)")
private String value;
} @Embeddable
public class MessageBundleIdEmbeddable {
@Column(name = "LOCALE", nullable = false, columnDefinition = "VARCHAR(2)")
private String locale;
@Column(name = "KEY", nullable = false, columnDefinition = "VARCHAR(256)")
private String key;
@Column(name = "BUNDLE", nullable = false, columnDefinition = "VARCHAR(256)")
private String bundle;
} Query MethodQMessageBundle messageBundle = QMessageBundle.messageBundle;
final BlazeJPAQuery<MessageBundle> query =
new BlazeJPAQuery<>(getEm(), getCriteriaBuilderFactory()).select(messageBundle)
.from(messageBundle);
if (StringUtils.isNotEmpty(criteria.getErrorCode())) {
query.where(messageBundle.id().key.containsIgnoreCase(criteria.getErrorCode()));
}
query.orderBy(messageBundle.id().key.lower());
query.fetchPage(criteria.getOffset(), criteria.getLimit()); Observed behaviourExecuting the query gives me this exception from
The error is correct since the keys are not unique. ProblemNone of my embeddable columns are unique. I tried to add all columns to the order by which would make the order persistent but since all columns themself are not unique the exception is still thrown. I'm starting the discussion to clarify if I need a different approach in my search or if this is currently a limitation. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Beta Was this translation helpful? Give feedback.
messageBundle.id().key.lower()
is entropy reducing, therefore uniqueness cannot be determined anymore and Blaze-Persistence rejects this kind of ordering for pagination purposes in order to provide deterministic results..orderBy(messagebundleId.id().key, messagebundleId.id().locale, messagebundleId.id().bundle)
.