Skip to content

Commit 6e9d0a9

Browse files
authored
Fix for @column on timestamp defined as timestamp(255) (#3740)
As per #3720 ``` @column ZonedDateTime zonedDateTime2; ``` ... resulting in DDL generated as `timestamp(255)`. This is occurring when the JPA dependency is used like: jakarta.persistence:jakarta.persistence-api:3.2.0 rather than using the transitive dependency that ebean includes. Workaround: Remove the jakarta.persistence:jakarta.persistence-api:3.2.0 dependency. Fix: The fix here is to use a timestamp type that has a maximum precision. When a precision/length is specified greater than the maximum precision then the fallback type is used which is `timestamp` without any precision.
1 parent a99ef3e commit 6e9d0a9

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

ebean-api/src/main/java/io/ebean/config/dbplatform/DbPlatformTypeMapping.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ protected void renderLengthScale(int deployLength, int deployScale, StringBuilde
5151
private static final DbPlatformType VECTOR_BIT = new DbPlatformType("bit", 64000, null);
5252
private static final DbPlatformType VECTOR_SPARSE = new DbPlatformType("sparsevec", 1000, null);
5353

54+
/**
55+
* Timestamp with max precision of 15, and fallback to plain timestamp without precision defined.
56+
*/
57+
private static final DbPlatformType TIMESTAMP =
58+
new DbPlatformType("timestamp", 0, 15,
59+
new DbPlatformType("timestamp", false));
60+
5461
private final Map<DbType, DbPlatformType> typeMap = new EnumMap<>(DbType.class);
5562

5663
/**
@@ -87,7 +94,8 @@ private void loadDefaults(boolean logicalTypes) {
8794
put(DbType.ARRAY);
8895
put(DbType.DATE);
8996
put(DbType.TIME);
90-
put(DbType.TIMESTAMP);
97+
put(DbType.TIMESTAMP, TIMESTAMP);
98+
9199
put(DbType.LONGVARBINARY);
92100
put(DbType.LONGVARCHAR);
93101
// most commonly real maps to db float

ebean-test/src/test/java/io/ebean/xtest/config/dbplatform/DbPlatformTypeMappingTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,29 @@
22

33
import io.ebean.config.dbplatform.DbPlatformType;
44
import io.ebean.config.dbplatform.DbPlatformTypeMapping;
5+
import io.ebean.config.dbplatform.DbType;
56
import org.junit.jupiter.api.Test;
67

78
import java.sql.Types;
89

910
import static org.assertj.core.api.Assertions.assertThat;
1011

11-
public class DbPlatformTypeMappingTest {
12+
class DbPlatformTypeMappingTest {
1213

1314
@Test
14-
public void logicalBoolean_renderType_expect_noLength() {
15+
void logicalBoolean_renderType_expect_noLength() {
1516

1617
DbPlatformTypeMapping logicalMapping = DbPlatformTypeMapping.logicalTypes();
1718

1819
DbPlatformType type = logicalMapping.get(Types.BOOLEAN);
1920
String colDefinition = type.renderType(1, 1, false);
2021
assertThat(colDefinition).isEqualTo("boolean");
2122
}
23+
24+
@Test
25+
void timestamp_with_255_expectNoPrecision() {
26+
DbPlatformType timestampType = new DbPlatformTypeMapping().get(DbType.TIMESTAMP);
27+
String colDefinition = timestampType.renderType(255, 0, true);
28+
assertThat(colDefinition).isEqualTo("timestamp");
29+
}
2230
}

0 commit comments

Comments
 (0)