Home Wrong ordering in generated table in jpa
Reply: 0

Wrong ordering in generated table in jpa

user2056
1#
user2056 Published in June 25, 2018, 12:01 am

This (should) be a rather simple thing to do, however I am struggling.

I want a table to be generated like this:

id 
organizationNumber 
name

However, when I look in the database, I see that the ordering is wrong. Does anybody know how I can force hibernate/jpa to generate the table with correct ordering?

desc Organization;
+--------------------+--------------+------+-----+---------+----------------+
| Field              | Type         | Null | Key | Default | Extra          |
+--------------------+--------------+------+-----+---------+----------------+
| id                 | bigint(20)   | NO   | PRI | NULL    | auto_increment | 
| name               | varchar(255) | NO   |     | NULL    |                | 
| organizationNumber | varchar(255) | NO   | UNI | NULL    |                | 
+--------------------+--------------+------+-----+---------+----------------+

This is how my entity bean looks like:

@Entity
@NamedQuery(name = "allOrganizations", query = "SELECT org FROM Organization org order by name")
public class Organization {

    private Long id;
    private String organizationNumber;
    private String name;

    public Organization() {
    }

    public Organization(String name) {
        this.name = name;
    }

    @Id
    @GeneratedValue
    public Long getId() {
        return id;
    }

    @SuppressWarnings("unused")
    private void setId(Long id) {
        this.id = id;
    }

    @NotEmpty
    @Column(unique=true, nullable=false)
    public String getOrganizationNumber() {
        return organizationNumber;
    }
       public void setOrganizationNumber(String organizationNumber) {
        this.organizationNumber = organizationNumber;
    }


    @NotEmpty
    @Column(nullable=false)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return this.name + " " + this.organizationNumber;
    }
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.313346 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO