jpa 中生成的表中的排序错误
这(应该)是一件相当简单的事情,但是我正在挣扎。
我希望生成一个如下表:
id organizationNumber name
但是,当我在数据库中查看时,我看到排序错误。有谁知道我如何强制休眠/ jpa以正确的顺序生成表?
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 | | +--------------------+--------------+------+-----+---------+----------------+
这是我的实体 Bean 的样子:
@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;
}
}