Benedikt Waldvogel (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiYmQzYjFkYTIz...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-17065?atlOrigin=eyJpIjoiYmQzYj...
) HHH-17065 (
https://hibernate.atlassian.net/browse/HHH-17065?atlOrigin=eyJpIjoiYmQzYj...
) Column ordering leads to wrong column order in composite primary keys (
https://hibernate.atlassian.net/browse/HHH-17065?atlOrigin=eyJpIjoiYmQzYj...
)
Issue Type: Bug Affects Versions: 6.2.7 Assignee: Unassigned Created: 09/Aug/2023 13:16 PM
Priority: Major Reporter: Benedikt Waldvogel (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
Note: This issue is very similar to
https://hibernate.atlassian.net/browse/HHH-16943 but
the same problem happens for *composite primary keys*.
-----
Given
-----
@Entity
@IdClass( CompositePrimaryKey.class )
static class TestEntity {
@Id private String b;
@Id private String a;
}
private static class CompositePrimaryKey {
private String b;
private String a;
// getters, setters, hashCode, equals
}
Note that we define the composite primary key on the columns *(b, a)* (in that very
order). The column order could be important since the underlying primary key index should
be used to speed-up queries that select all entities for a given value of “b”.
-------------------
Actual vs. Expected
-------------------
When the schema gets created in the context of a JPA EntityManagerFactory, the columns are
(re-)ordered during construction of the SessionFactoryImpl, Line 252:
bootMetamodel.orderColumns( false ) (
https://github.com/hibernate/hibernate-orm/blob/58aff00957721074a4a393725...
)
This leads to the following DDL:
create table "TestEntity" (
a varchar (255) not null ,
b varchar (255) not null ,
primary key ( a , b)
)
Note that the primary key is created for *(a, b)* instead of the expected column order
*(b, a)*.
----------
Workaround
----------
One can restore the behavior of Hibernate 6.1 by switching to the legacy column ordering
strategy via hibernate.column_ordering_strategy=legacy.
---------
Test Case
---------
Upcoming…
(
https://hibernate.atlassian.net/browse/HHH-17065#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-17065#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100234- sha1:90f5128 )