Ivan Vakhrushev (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5c3c198...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNGRmYjE3ZmE2...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16953?atlOrigin=eyJpIjoiNGRmYj...
) HHH-16953 (
https://hibernate.atlassian.net/browse/HHH-16953?atlOrigin=eyJpIjoiNGRmYj...
) Hibernate doesn't observe column order on multicolumn indexes (
https://hibernate.atlassian.net/browse/HHH-16953?atlOrigin=eyJpIjoiNGRmYj...
)
Issue Type: Bug Affects Versions: 6.2.5 Assignee: Unassigned Created: 18/Jul/2023 01:03 AM
Environment: Spring Boot 3.1.1
Hibernate 6.2.5.Final
PostgreSQL
Java 17
MacOS Labels: breaking-change Priority: Minor Reporter: Ivan Vakhrushev (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5c3c198...
)
While trying to migrate to Spring Boot 3.1 I faced with an issue related to Hibernate
6.2.5.Final and index generation.
I use automatic schema generation ( hibernate.hbm2ddl.auto = create )
I have an entity with unique index on it (
https://github.com/mfvanek/salary-calc/blob/f14848fc6f50ae22ebd0490eabb5e...
).
@NoArgsConstructor
@SuperBuilder
@Getter
@Setter
@Entity
@Table(
name = "tickets" ,
indexes = {
@Index(name = "idx_tickets_employee_date" , columnList =
"emp_id,calculated_at,is_active" , unique = true )
}
)
@Comment( "Table for tickets" )
public class Ticket {
@Id
@NotNull
@Column(updatable = false , nullable = false )
private UUID id;
@Column(name = "created_at" , updatable = false , nullable = false )
private LocalDateTime createdAt;
@Column(name = "updated_at" , insertable = false )
private LocalDateTime updatedAt;
@NotNull
@Column(name = "calculated_at" , updatable = false , nullable = false )
private LocalDate calculationDate;
@NotNull
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "emp_id" , updatable = false , nullable = false )
private Employee employeeId;
@Column(name = "is_active" )
private Boolean isActive;
}
On Spring Boot 3.0.8 and Hibernate 6.1.7.Final everything works as expected:
Hibernate: alter table if exists tickets add constraint idx_tickets_employee_date unique
(emp_id, calculated_at, is_active)
Unique index is created with proper columns order.
On Spring Boot 3.1.1 and Hibernate 6.2.5.Final I've got
Hibernate: create table tickets (calculated_at date not null, is_active boolean,
created_at timestamp(6) not null, updated_at timestamp(6), emp_id uuid not null, id uuid
not null, primary key (id), constraint idx_tickets_employee_date unique (calculated_at,
is_active, emp_id))
with reordered columns
This isn't what I expected!
JPA says: "The persistence provider must observe the specified ordering of the
columns."
https://download.oracle.com/otndocs/jcp/persistence-2_1-fr-eval-spec/inde...
Example here
https://github.com/mfvanek/salary-calc/tree/hibernate-bug
(
https://hibernate.atlassian.net/browse/HHH-16953#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16953#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#100232- sha1:4a3b42c )