Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Column order on OpenJPA

Tags:

jpa

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.

like image 847
Mariana Franco Avatar asked Jun 04 '13 21:06

Mariana Franco


People also ask

What is order column?

The OrderColumn annotation is specified on the side of the relationship that references the collection that is to be ordered. The order column is not visible as part of the state of the entity or embeddable class.

What is order column in hibernate?

@OrderColumn is used to store list index. As list is ordered collection, so to maintain the list index there can be a column in database and while inserting the data, list index will be stored in that column. For this the property in entity should be annotated with. @OrderColumn (name="column-name")

Does the order of columns matter in a relation?

In a relation, the order of the columns does not matter.

How@ OrderColumn works?

@OrderColumn annotation specifies a column that should maintain the persistent order of a list. The persistence provider maintains the order and also updates the ordering on insertion, deletion, or reordering of the list. This annotation can be used on @OneToMany or @ManyToMany relationship or on @ElementCollection .


1 Answers

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.

like image 51
Óscar López Avatar answered Dec 07 '22 16:12

Óscar López