开发者

JPA and order of columns in the database

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开发者_StackOverflow中文版've understood hibernate order columns alphabetically but I can't find any specifications for Eclipselink.


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.

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);
  }
}

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜