Saving order of a List in JPA

前端 未结 3 1396
粉色の甜心
粉色の甜心 2021-02-01 03:45

I have the following question about JPA:

Can I save the order of the elements in a java.util.List? In my application the order in which I put elements in the Lists is im

相关标签:
3条回答
  • 2021-02-01 04:14

    JPA has 2 types of Lists. In JPA1 there is an "ordered list" (which is what you see, ordering defined by some SQL clause). In JPA2 you can have "ordered lists" or alternatively "indexed lists" (where the order of creation is preserved) ... the @OrderColumn referred to. Any implementation of JPA2 will have to support this e.g DataNucleus.

    JDO has had indexed lists since day 1

    0 讨论(0)
  • 2021-02-01 04:14

    You can save the order of the elements in a java.util.List. In JPA 2.0, There is the good way to save the order of element by using @OrderColumn annotation.

    For the details, you can refer this link Order Column (JPA 2.0)

    0 讨论(0)
  • 2021-02-01 04:15

    There are some hacky ways of doing this in JPA 1, but it's easiest to switch to a JPA 2 provider. The @OrderColumn annotation support is what you're looking for. Eclipselink have an ok tutorial on how to use it.

    0 讨论(0)
提交回复
热议问题