How to Fix Column Order Mismatch in Spring Boot 3.3.5 JPA Auto‑Generated Tables
Upgrading to Spring Boot 3.3.5 can cause Hibernate to generate table columns in a different order than the fields in your @Entity class, but by copying and adjusting the PropertyContainer class you can restore the original field order and avoid schema inconsistencies.
After upgrading Spring Boot to version 3.3.5, the columns created automatically by Spring Data JPA no longer follow the order of the fields defined in the Entity class, leading to mismatched table structures.
Problem Example
@Data
@Entity(name = "t_config")
@EntityListeners(AuditingEntityListener.class)
public class Config {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(length = 20)
private String itemKey;
@Column(length = 200)
private String itemValue;
@Column(length = 200)
private String itemDesc;
@CreatedDate
private Date createTime;
@LastModifiedDate
private Date modifyTime;
}The generated table shows columns in a different order than the fields above:
Old Version Solution
The classic fix replaces the Hibernate implementation by copying and modifying the PropertyContainer class:
Create a package org.hibernate.cfg in your project.
Copy PropertyContainer from hibernate-core (under org.hibernate.cfg) into the newly created package.
Change the field persistentAttributeMap type from TreeMap to LinkedHashMap in the copied class.
Solution for Spring Boot 3.3.5
In the newer Hibernate version the class location and internal fields have changed, so the steps are slightly different:
Create a package org.hibernate.boot.model.internal in your project.
Copy the updated PropertyContainer class from hibernate-core (under org.hibernate.boot.model.internal) into the new package.
Replace the initialization of localAttributeMap from new TreeMap<>() to new LinkedHashMap<>() in the copied class.
Relevant excerpt of the new PropertyContainer class (truncated for brevity):
package org.hibernate.boot.model.internal;
// ... other imports ...
public class PropertyContainer {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, PropertyContainer.class.getName());
private final XClass xClass;
private final XClass entityAtStake;
private final AccessType classLevelAccessType;
private final List<XProperty> persistentAttributes;
// ... other members ...
}The two key changes are:
The package moved from org.hibernate.cfg to org.hibernate.boot.model.internal.
The old TreeMap<String, XProperty> persistentAttributeMap field was removed and replaced by a List<XProperty> persistentAttributes field.
After applying these modifications, the column order generated by JPA matches the field order in the Entity class, resolving the issue introduced by the Spring Boot upgrade.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
