gpt4 book ai didi

java - jpa中生成的表中的错误排序

转载 作者:IT老高 更新时间:2023-10-28 20:29:06 26 4
gpt4 key购买 nike

这(应该)是一件相当简单的事情,但是我很挣扎。

我想要这样生成一个表格:

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;
}
}

最佳答案

Hibernate 按字母 顺序生成列。根据this post原因如下:

It is sorted to ensurce deterministicordering across clusters.

We can't rely on the vm to return themethods in the same order every timeso we had to do something.

显然它曾经是按发生顺序排列的,但这在 3.2.0 GA 和 3.2.1 GA 之间发生了变化。

我还找到了 Schema auto generation creates columns in alphabetical order for compound primary keys这似乎是你的问题。这张票是关于主键顺序变化的,这会对索引性能产生负面影响。

除了以正确的顺序命名列的解决方法(不,我不是在开玩笑)之外,没有其他解决方法。

关于java - jpa中生成的表中的错误排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1298322/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com