Skip to content

Commit d3b7002

Browse files
dkayiwaclaude
andcommitted
Fix Hibernate 7.4 dropping primary key on order_type_class_map join table
Hibernate 7.4 emits a unique constraint instead of a composite primary key when a @jointable's explicit @UniqueConstraint covers exactly the columns that would form the join table's primary key. OrderType was the only @manytomany Set declaring such a redundant @UniqueConstraint, so its order_type_class_map join table lost its primary key under hbm2ddl. This broke the integration tests, whose dbUnit REFRESH operation needs a primary key to update existing rows (NoPrimaryKeyException). Remove the redundant @UniqueConstraint: the two FK columns are the natural key of a Set join table, so hbm2ddl generates the composite primary key again, matching the production schema that already defines it via Liquibase. The annotation only affected hbm2ddl-generated DDL, so production is unaffected. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 9282315 commit d3b7002

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

api/src/main/java/org/openmrs/OrderType.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import jakarta.persistence.ManyToMany;
2424
import jakarta.persistence.ManyToOne;
2525
import jakarta.persistence.Table;
26-
import jakarta.persistence.UniqueConstraint;
2726

2827
import org.apache.commons.lang3.StringUtils;
2928
import org.hibernate.envers.Audited;
@@ -62,8 +61,7 @@ public class OrderType extends BaseChangeableOpenmrsMetadata {
6261

6362
@Independent
6463
@ManyToMany
65-
@JoinTable(name = "order_type_class_map", joinColumns = @JoinColumn(name = "order_type_id"), inverseJoinColumns = @JoinColumn(name = "concept_class_id"), uniqueConstraints = @UniqueConstraint(columnNames = {
66-
"order_type_id", "concept_class_id" }))
64+
@JoinTable(name = "order_type_class_map", joinColumns = @JoinColumn(name = "order_type_id"), inverseJoinColumns = @JoinColumn(name = "concept_class_id"))
6765
private Set<ConceptClass> conceptClasses;
6866

6967
/**

0 commit comments

Comments
 (0)