Home > Java > javaTutorial > body text

How to Control Column Ordering in JPA Generated Tables?

Susan Sarandon
Release: 2024-10-27 13:11:30
Original
340 people have browsed it

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!