JPA和数据库中的列顺序 [英] JPA and order of columns in the database

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

问题描述

我正在使用Eclipselink作为我的持久性提供程序。有没有办法指定列在数据库中的显示顺序?数据库中的列顺序与我的实体中的属性顺序不匹配。据我所知,按字母顺序排列hibernate订单列,但我找不到Eclipselink的任何规范。

I'm using Eclipselink as my persistence provider. Is there any way to specify the order in which the columns appear in the database? The column-order in the database doesn't match the attribute-order in my entities. As far as I've understood hibernate order columns alphabetically but I can't find any specifications for Eclipselink.

推荐答案

EclipseLink对根据映射的权重映射,从而映射它们的列。通常不设置权重,除了确保Baisc映射是第一个,关系映射是第二个。

EclipseLink sorts the mappings and thus their columns based on the weight of the mapping. Normally the weight is not set other than to ensure that Baisc mappings are first, and relationship mappings are second.

如果您希望使用a,您可以设置映射的权重DescriptorCustomizer。您还可以将描述符设置为不按权重排序映射,因此将使用它们指定的顺序(setShouldOrderMappings(false))。

You can set the weight for a mapping if you desire using a DescriptorCustomizer. You could also set the descriptor to not order mapping by weight, so the order that they were specified will be used (setShouldOrderMappings(false)).

public void MyCustomizer implements DescriptorCustomizer {
  public void customize(ClassDescriptor descriptor) {
    descriptor.getMappingForAttributeName("name").setWeight(2);
  }
}

最近对映射权重进行了一些更改在2.2开发中,映射现在按相同的权重级别按名称排序。

There have been some recent changes to the weighting of mappings in the 2.2 development, the mappings are now sorted by name within the same weight levels.

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

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