Mariana Franco
Mariana Franco

Reputation: 297

Column order on OpenJPA

Is there a way to get the columns in the order they are declared in the Java class, or to specify the order in some other way?

I'm using the mapping tool ant task to generate the DDL for my classes in a sql file.

Upvotes: 7

Views: 1529

Answers (1)

Óscar López
Óscar López

Reputation: 236004

No, each implementation of JPA is free to arrange the columns in the generated DDL in the order it sees fit, and in general the programmer has no control over this - for example: Hibernate uses alphabetical order, but DataNucleus allows the specification of a column position thanks to a non-standard annotation. Sadly, OpenJPA doesn't provide a mechanism for specifying column ordering.

I had a similar problem a while ago, the data base guidelines of my client mandated a certain ordering in the columns and my JPA provider produced a different order. The solution? we wrote a text-processing Java program that, given the generated DDL as input, reordered the columns in the code so it satisfied the guidelines and produced as output a new file with the modified DDL; the program was run from an Ant task. Not pretty, but from a practical standpoint it was the best solution we could muster.

Upvotes: 7

Related Questions