Skip to content

Commit 5ff4c80

Browse files
committed
HHH-19749 set the correct default decimal precision for both Oracle and SQL Server
1 parent d468dfa commit 5ff4c80

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,11 @@ public boolean supportsInsertReturningGeneratedKeys() {
507507
return true;
508508
}
509509

510+
@Override
511+
public int getDoublePrecision() {
512+
return 38;
513+
}
514+
510515
/**
511516
* type or {@link Types#TIME} type, and its default behavior
512517
* for casting dates and timestamps to and from strings is just awful.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,11 @@ public int getMaxIdentifierLength() {
346346
return 128;
347347
}
348348

349+
@Override
350+
public int getDoublePrecision() {
351+
return 38;
352+
}
353+
349354
@Override
350355
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
351356
super.contributeTypes( typeContributions, serviceRegistry );
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.secondarytable;
6+
7+
import jakarta.persistence.Column;
8+
import jakarta.persistence.Entity;
9+
import jakarta.persistence.GeneratedValue;
10+
import jakarta.persistence.Id;
11+
import jakarta.persistence.SecondaryTable;
12+
import jakarta.persistence.Table;
13+
import org.hibernate.annotations.JdbcType;
14+
import org.hibernate.dialect.OracleDialect;
15+
import org.hibernate.dialect.SQLServerDialect;
16+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
17+
import org.hibernate.testing.orm.junit.JiraKey;
18+
import org.hibernate.testing.orm.junit.Jpa;
19+
import org.hibernate.testing.orm.junit.RequiresDialect;
20+
import org.hibernate.testing.orm.junit.Setting;
21+
import org.hibernate.type.descriptor.jdbc.NumericJdbcType;
22+
import org.junit.jupiter.api.Test;
23+
24+
@Jpa(
25+
annotatedClasses = {MergeCastNumericTest.Actor.class},
26+
integrationSettings = {
27+
@Setting(name = org.hibernate.cfg.AvailableSettings.SHOW_SQL, value = "true"),
28+
}
29+
)
30+
@JiraKey("HHH-19749")
31+
@RequiresDialect(OracleDialect.class)
32+
@RequiresDialect(SQLServerDialect.class)
33+
class MergeCastNumericTest {
34+
35+
@Test
36+
void test(EntityManagerFactoryScope scope) {
37+
scope.inTransaction(
38+
entityManager -> {
39+
Actor actor = new Actor();
40+
actor.salary = 5000.77d;
41+
42+
entityManager.persist( actor );
43+
entityManager.flush();
44+
entityManager.clear();
45+
46+
actor = entityManager.find( Actor.class, actor.id );
47+
actor.salary = 5000.88d;
48+
49+
entityManager.flush();
50+
entityManager.clear();
51+
}
52+
);
53+
}
54+
55+
@Entity(name = "actor")
56+
@Table(name = "PRINCIPAL")
57+
@SecondaryTable(name = "SECONDARY")
58+
public static class Actor {
59+
@Id
60+
@GeneratedValue
61+
private Long id;
62+
@Column(table = "SECONDARY", precision = 6, scale = 2)
63+
@JdbcType(NumericJdbcType.class)
64+
private double salary;
65+
}
66+
}

0 commit comments

Comments
 (0)