Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

play creates tables with the fields sorted alphabetically

I am using a model in Play like this:

package models;

import java.util.*;
import javax.persistence.*;

import play.db.jpa.*;

@Entity
public class User extends Model {

    public String email;
    public String password;
    public String fullname;
    public boolean isAdmin;

    public User(String email, String password, String fullname) {
        this.email = email;
        this.password = password;
        this.fullname = fullname;
    }

}

Then, the table created by Play! has fields sorted alphabetically like:

id
email
fullname
isAdmin
password

Is there any way to have it in the right order?

like image 478
dotoree Avatar asked Jan 31 '26 12:01

dotoree


1 Answers

Play uses Hibernate. Hibernate orders the columns when it creates the tables. See this discussion:

It is sorted to ensurce deterministic ordering across clusters.

To get a different order, let Hibernate create the DDLs for the tables and sort the columns the way you like.

That is: Don't let Play/Hibernate create the tables automatically. Instead, create them manually.

like image 172
Aaron Digulla Avatar answered Feb 03 '26 02:02

Aaron Digulla