Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JPA and EmbeddedId: various issues #603

jmescheder opened this issue Oct 24, 2019 · 2 comments


Copy link

@jmescheder jmescheder commented Oct 24, 2019

Hi there, first of all, I am very impressed with the framework so far. Thanks!
I stumbled upon some issues related to JPA Entities using composite primary keys as an EmbeddedId and sorting.

Let's say, we have the following Entity:
class A {
B b;

String e;

This is the embedded ID class:
class B {
// d is defined before c, as we need the generated id in the json to be "d-c"
// c is also some kind of sub-category of d, so we want standard sorting to be d, c
private Integer d;
private Integer c;

These are the SQL order by clauses that various request sort parameters produce:

  1. no sort parameter provided
    order by c, d asc
    expected: order by d, c
  2. sort=id
    order by c, d asc
    expected: order by d, c
  3. sort=-id
    order by c, d desc
    expected: order by d desc, c desc
  4. sort=-id.c
    order by c desc, c, d asc
    expected: order by c desc, d
    (real problem: considered wrong syntax by most databases)

This comment has been minimized.

Copy link

@remmeier remmeier commented Oct 25, 2019

thank you! can have a look when being back on sunday. the issue linely resides around the CriteriaQueryFactory that tranlates QuerySpec to a JPA query

remmeier added a commit that referenced this issue Nov 9, 2019
Hibernate sorting of embeddables seems unreliable:
- column sort order does not reflect attribute order in class
- direction only honored for one attribute

Embeddables now sorted manually:
- order of attributes and direction honored
- total order mechanism will ignore already sorted primary key attributes (this too also avoid sorting the same field in two directions since total order is always ASC).

This comment has been minimized.

Copy link

@remmeier remmeier commented Nov 9, 2019

sorting now down manually for embeddables: honors order of attributes as defined in class, honors direction for all attributes and total order will only sort the missing pieces in ASC order.

official 3.1 release to follow this weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.