Home  >  Article  >  Java  >  How to Control Column Ordering in JPA Generated Tables?

How to Control Column Ordering in JPA Generated Tables?

Susan Sarandon
Susan SarandonOriginal
2024-10-27 13:11:30326browse

How to Control Column Ordering in JPA Generated Tables?

Issue: Incorrect Ordering of Generated Database Table in JPA

In an attempt to create a table with specific column ordering, you encountered a discrepancy where the generated table had the order changed. You have created an entity bean and specified the desired ordering using the @Column annotation, but the database table's column order remains incorrect.

Explanation:

Hibernate generates database columns alphabetically by default. This is done to ensure deterministic ordering across clusters, even though earlier versions of Hibernate allowed order based on occurrence.

Solution:

Since Hibernate enforces alphabetical ordering, the only workaround available is to manually change the column names in the entity bean in a way that reflects the desired ordering. For example:

<code class="java">@Column(name = "orgNumber")
public String getOrganizationNumber() { ... }

@Column(name = "orgName")
public String getName() { ... }</code>

This will ensure that the table columns are generated in the order specified by the new column names.

The above is the detailed content of How to Control Column Ordering in JPA Generated Tables?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn