fatcheung
V2EX  ›  问与答

Spring data Jpa 不写 SQL 的话怎么排 NULL 值在最后(DESC),求问?

  •  
  •   fatcheung · Jun 6, 2018 · 2885 views
  •   You need to sign in to view this topic
    This topic created in 2910 days ago, the information mentioned may be changed or developed.

    用 nullslast 方法不起作用。貌似这是个 BUG ?有知道的吗,谢谢。

    8 replies    2018-06-06 18:32:49 +08:00
    alvinbone88
        1
    alvinbone88  
       Jun 6, 2018
    MySQL 的锅
    所以说在设计表的时候不应该允许插入 NULL
    fatcheung
        2
    fatcheung  
    OP
       Jun 6, 2018
    @alvinbone88 我觉得是 JPA 的锅,用 SQL 的话是可以做到的( NULLS LAST ),但是拼接 SQL 太麻烦了,字段太多。
    我英文不太好,这个链接说的是 JPA 有 bug 没有修复吧?谢谢你。
    https://stackoverflow.com/questions/50403298/any-workaround-for-the-openjpa-to-do-order-by-nulls-last-first-query
    alvinbone88
        3
    alvinbone88  
       Jun 6, 2018
    letitbesqzr
        4
    letitbesqzr  
       Jun 6, 2018
    不关 jpa 的事吧,jpa 就是个接口,而且提供的有 nullsFirst 的方法。你要用的 hibernate 的 jpa 实现,那就应该是 hibernate 的锅吧。
    fatcheung
        5
    fatcheung  
    OP
       Jun 6, 2018
    @alvinbone88 这个看过了,打印出的 SQL 确实没有在 Order By 后面加 nulls last,所以我说是 BUG 了。
    fatcheung
        6
    fatcheung  
    OP
       Jun 6, 2018
    @letitbesqzr 你有用过 hibernate 吗?它那个 nullslast 能用吗?我用的 Jpa,可能没有封装到。
    honeycomb
        7
    honeycomb  
       Jun 6, 2018 via Android
    @fatcheung 如果是 bug 就应该到 hibernate 的项目上提 issue 不是?
    fatcheung
        8
    fatcheung  
    OP
       Jun 6, 2018
    @honeycomb 好像是 Spring Data Jpa 的 bug,而且好像有人提过了,这个项目应该是关闭了 issue,我找不到。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3179 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 466ea39e · 34ms · UTC 13:31 · PVG 21:31 · LAX 06:31 · JFK 09:31
    ♥ Do have faith in what you're doing.