1

Possible Duplicate:
Wrong ordering in generated table in jpa

Im using Play! framework, and i have this in my model:

@Entity(name="Dialer")
public class Dialer extends Model {
    @Column(name="offer")
    public String offer;
    @Column(name="domain")
    public String domain;
    @Column(name="created_date", insertable=false, updatable=false) 
    @Generated(value=GenerationTime.ALWAYS) 
    @Temporal(TemporalType.TIMESTAMP)
    public DateTime createdDate;
    ......

I would expect this to be reflected in the database exactly as its laid out but instead i get this:

id, created_date, domain, offer

How do i fix this?

Community
  • 1
  • 1
Javier Buzzi
  • 6,296
  • 36
  • 50
  • 3
    Why does it matter? The column order should not be not significant. – Aleksi Yrttiaho Jun 08 '11 at 04:07
  • Similar and yet not in related list: http://stackoverflow.com/questions/5964714/maintain-the-order-of-column-when-creating-a-new-table-using-hibernate, http://stackoverflow.com/questions/4323065/jpa-and-order-of-columns-in-the-database, – Aleksi Yrttiaho Jun 08 '11 at 04:44
  • Have you tried if the order is persisted if you use a mapping file instead of annotations? The annotations may be handled in any order - not only in the order they are written. You might also want to read the documentation of the JPA implementation as it may have extensions that allow column order to specified explicitly – Aleksi Yrttiaho Jun 08 '11 at 04:49
  • I'm sorry if these comments upset you. My intention was to 1) determine the motivation as not all understand the lack of meaning in the column order 2) Connect this to other Stack Overflow questions so that the different users with different agendas may be served a bit better 3) understand why the column order is what it is and what can be done about it. I understand that the part 3 is the only one that might help you and it would be ideal that you'd get a short and simple answer. – Aleksi Yrttiaho Jun 08 '11 at 04:55
  • Trust me im not upset, a bit frustrated -- but i've been programming long enough to know that it comes with the territory. – Javier Buzzi Jun 08 '11 at 05:22

2 Answers2

4

This has been answered. Hibernate sorts columns alphabetically.

Wrong ordering in generated table in jpa

Community
  • 1
  • 1
qeek
  • 2,010
  • 2
  • 16
  • 23
0

JPA does not define a way of controlling the schema generation column order for a table; it is implementation-dependent. JDO does define a mechanism.

DataNucleus
  • 15,497
  • 3
  • 32
  • 37
  • JDO's mechanism allows a user to specify a field with @Column(position={x}) where {x} is an integer, so you can order all columns. Obviously Hibernate doesn't support JDO anyway. Whether your JPA implementation provides a way of doing this is down to what you're using, and reading their docs. – DataNucleus Jun 08 '11 at 08:33