-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-17795 fix an NPE and add a test for 'on conflict on constraint'
- Loading branch information
Showing
4 changed files
with
48 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...e-core/src/test/java/org/hibernate/orm/test/query/hql/InsertConflictOnConstraintTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.hibernate.orm.test.query.hql; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import jakarta.persistence.UniqueConstraint; | ||
import org.hibernate.dialect.PostgreSQLDialect; | ||
import org.hibernate.testing.orm.junit.DomainModel; | ||
import org.hibernate.testing.orm.junit.RequiresDialect; | ||
import org.hibernate.testing.orm.junit.SessionFactory; | ||
import org.hibernate.testing.orm.junit.SessionFactoryScope; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@SessionFactory | ||
@DomainModel(annotatedClasses = InsertConflictOnConstraintTest.Constrained.class) | ||
@RequiresDialect(PostgreSQLDialect.class) | ||
public class InsertConflictOnConstraintTest { | ||
@Test void test(SessionFactoryScope scope) { | ||
scope.inTransaction( s -> s.persist(new Constrained())); | ||
scope.inTransaction( s -> s.createMutationQuery("insert into Constrained(id, name, count) values (4,'Gavin',69) on conflict on constraint constrained_count_name_key do update set count = 96").executeUpdate()); | ||
scope.inSession( s -> assertEquals(96, s.createSelectionQuery("select count from Constrained", int.class).getSingleResult())); | ||
|
||
} | ||
|
||
@Entity(name = "Constrained") | ||
@Table(uniqueConstraints = @UniqueConstraint(columnNames = {"count","name"})) | ||
static class Constrained { | ||
@Id | ||
@GeneratedValue | ||
long id; | ||
String name = "Gavin"; | ||
int count = 69; | ||
} | ||
|
||
} |