在JPA中保存列表的顺序 [英] Saving order of a List in JPA

查看:323
本文介绍了在JPA中保存列表的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有关于JPA的以下问题:

I have the following question about JPA:

我可以保存java.util.List中元素的顺序吗?在我的应用程序中,我将元素放在列表中的顺序很重要,但在我从数据库中获取这些集合后,顺序不一样(如预期的那样)。你能告诉我一个解决这个问题的方法吗?

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 important but after I get those collections from the database the order is not the same (as expected). Can you show me a way to deal with this problem?

P.S。在我收集的实体中没有一个字段可供我订购。

P.S. There is not a field in the entities that I put in the collections by which I can order them.

Rosen

推荐答案

在JPA 1中有一些hacky方法可以做到这一点,但最简单的方法是切换到JPA 2提供程序。 @OrderColumn注释支持是您正在寻找的。 Eclipselink有一个关于如何使用它的正确教程

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.

这篇关于在JPA中保存列表的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆