Skip to content

Commit 42725e9

Browse files
committed
HHH-19608 Sybase also requires that partition keys belong to PK
but disable the test because I can't run a command as sa
1 parent a63f05e commit 42725e9

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

hibernate-core/src/main/java/org/hibernate/dialect/SybaseDialect.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,11 @@ public boolean supportsRowValueConstructorSyntaxInInList() {
579579
return false;
580580
}
581581

582+
@Override
583+
public boolean addPartitionKeyToPrimaryKey() {
584+
return true;
585+
}
586+
582587
private static class JTDSSchemaNameResolver implements SchemaNameResolver {
583588
@Override
584589
public String resolveSchemaName(Connection connection, Dialect dialect) throws SQLException {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.sql.partition;
6+
7+
import jakarta.persistence.Entity;
8+
import jakarta.persistence.Id;
9+
import jakarta.persistence.Table;
10+
import org.hibernate.annotations.PartitionKey;
11+
import org.hibernate.dialect.SybaseASEDialect;
12+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
13+
import org.hibernate.testing.orm.junit.FailureExpected;
14+
import org.hibernate.testing.orm.junit.Jpa;
15+
import org.hibernate.testing.orm.junit.RequiresDialect;
16+
import org.junit.jupiter.api.Test;
17+
18+
import static org.junit.jupiter.api.Assertions.assertNotNull;
19+
20+
// MUST RUN AS USER sa:
21+
// sp_configure 'enable semantic partitioning', 1
22+
@RequiresDialect(SybaseASEDialect.class)
23+
@Jpa(annotatedClasses = SybasePartitionedTableTest.Partitioned.class)
24+
@FailureExpected(reason = "can't configure 'enable semantic partitioning'")
25+
class SybasePartitionedTableTest {
26+
@Test void test(EntityManagerFactoryScope scope) {
27+
scope.inTransaction( session -> {
28+
Partitioned partitioned = new Partitioned();
29+
partitioned.id = 1L;
30+
partitioned.pid = 500L;
31+
session.persist( partitioned );
32+
} );
33+
scope.inTransaction( session -> {
34+
Partitioned partitioned = session.find( Partitioned.class, 1L );
35+
assertNotNull( partitioned );
36+
partitioned.text = "updated";
37+
} );
38+
}
39+
@Entity
40+
@Table(name = "syparts",
41+
options =
42+
"""
43+
PARTITION BY RANGE (pid) (
44+
p1 VALUES <= (1000),
45+
p2 VALUES <= (2000)
46+
)
47+
""")
48+
static class Partitioned {
49+
@Id Long id;
50+
@PartitionKey Long pid;
51+
String text = "";
52+
}
53+
}

0 commit comments

Comments
 (0)