Skip to content

Commit 5975d02

Browse files
VladoKurucsebersole
authored andcommitted
Tests with current_timestamp requires Dialect UsesStandardCurrentTimestampFunction feature
1 parent d90807f commit 5975d02

File tree

9 files changed

+49
-57
lines changed

9 files changed

+49
-57
lines changed

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,11 @@ public void appendDatetimeFormat(SqlAppender appender, String format) {
661661
appender.appendSql( datetimeFormat( format ).result() );
662662
}
663663

664+
@Override
665+
public boolean supportsStandardCurrentTimestampFunction() {
666+
return false;
667+
}
668+
664669
public static Replacer datetimeFormat(String format) {
665670
return new Replacer( format, "'", "" )
666671
.replace("%", "%%")

hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/ComplexValueGenerationTests.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,14 @@
2525
import org.hibernate.annotations.CreationTimestamp;
2626
import org.hibernate.annotations.Generated;
2727
import org.hibernate.annotations.UpdateTimestamp;
28-
import org.hibernate.dialect.MySQLDialect;
29-
import org.hibernate.dialect.SybaseDialect;
30-
import org.hibernate.dialect.TiDBDialect;
3128
import org.hibernate.generator.EventType;
3229

30+
31+
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
3332
import org.hibernate.testing.orm.junit.DomainModel;
33+
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
3434
import org.hibernate.testing.orm.junit.SessionFactory;
3535
import org.hibernate.testing.orm.junit.SessionFactoryScope;
36-
import org.hibernate.testing.orm.junit.SkipForDialect;
3736
import org.junit.jupiter.api.AfterEach;
3837
import org.junit.jupiter.api.Test;
3938

@@ -47,9 +46,9 @@
4746
/**
4847
* @author Steve Ebersole
4948
*/
50-
@SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true, reason = "CURRENT_TIMESTAMP not supported as default value in Sybase")
51-
@SkipForDialect(dialectClass = MySQLDialect.class, reason = "See HHH-10196")
52-
@SkipForDialect(dialectClass = TiDBDialect.class, reason = "See HHH-10196")
49+
50+
@RequiresDialectFeature( feature = DialectFeatureChecks.CurrentTimestampHasMicrosecondPrecision.class )
51+
@RequiresDialectFeature( feature = DialectFeatureChecks.UsesStandardCurrentTimestampFunction.class )
5352
@DomainModel( annotatedClasses = ComplexValueGenerationTests.AuditedEntity.class )
5453
@SessionFactory
5554
@SuppressWarnings("JUnitMalformedDeclaration")

hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/DatabaseValueGenerationTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@
1313

1414
import org.hibernate.annotations.ValueGenerationType;
1515
import org.hibernate.dialect.Dialect;
16-
import org.hibernate.dialect.SybaseDialect;
1716
import org.hibernate.generator.EventType;
1817
import org.hibernate.generator.EventTypeSets;
1918
import org.hibernate.generator.OnExecutionGenerator;
2019
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
2120

22-
import org.hibernate.testing.SkipForDialect;
2321
import org.junit.Test;
2422

2523
import jakarta.persistence.Column;
@@ -32,7 +30,6 @@
3230
/**
3331
* @author Vlad Mihalcea
3432
*/
35-
@SkipForDialect(value = SybaseDialect.class, comment = "Sybase doesn't seem to support current_timestamp")
3633
public class DatabaseValueGenerationTest extends BaseEntityManagerFunctionalTestCase {
3734

3835
@Override

hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/DefaultGeneratedValueIdentityTest.java

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import java.lang.annotation.Retention;
1010
import java.lang.annotation.RetentionPolicy;
11-
import java.lang.reflect.Member;
1211
import java.sql.Time;
1312
import java.sql.Timestamp;
1413
import java.time.Instant;
@@ -31,52 +30,42 @@
3130
import org.hibernate.annotations.UpdateTimestamp;
3231
import org.hibernate.annotations.ValueGenerationType;
3332
import org.hibernate.dialect.Dialect;
34-
import org.hibernate.dialect.MySQLDialect;
35-
import org.hibernate.dialect.SybaseDialect;
36-
import org.hibernate.generator.AnnotationBasedGenerator;
3733
import org.hibernate.generator.EventType;
38-
import org.hibernate.generator.GeneratorCreationContext;
3934
import org.hibernate.generator.OnExecutionGenerator;
4035

41-
import org.hibernate.testing.DialectChecks;
42-
import org.hibernate.testing.RequiresDialectFeature;
43-
import org.hibernate.testing.SkipForDialect;
44-
import org.hibernate.testing.TestForIssue;
45-
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
46-
import org.junit.Test;
36+
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
37+
import org.hibernate.testing.orm.junit.DomainModel;
38+
import org.hibernate.testing.orm.junit.JiraKey;
39+
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
40+
import org.hibernate.testing.orm.junit.SessionFactory;
41+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
42+
import org.junit.jupiter.api.AfterEach;
43+
import org.junit.jupiter.api.Test;
4744

4845
import jakarta.persistence.Column;
4946
import jakarta.persistence.Entity;
5047
import jakarta.persistence.GeneratedValue;
5148
import jakarta.persistence.GenerationType;
5249
import jakarta.persistence.Id;
5350

54-
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
5551
import static org.junit.Assert.assertEquals;
5652
import static org.junit.Assert.assertNotNull;
5753
import static org.junit.Assert.assertNull;
5854

59-
@SkipForDialect(value = SybaseDialect.class, comment = "CURRENT_TIMESTAMP not supported as default value in Sybase")
60-
@SkipForDialect(value = MySQLDialect.class, comment = "See HHH-10196")
61-
@RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class)
62-
public class DefaultGeneratedValueIdentityTest extends BaseCoreFunctionalTestCase {
63-
64-
@Override
65-
protected Class<?>[] getAnnotatedClasses() {
66-
return new Class[] { TheEntity.class };
67-
}
68-
69-
@Override
70-
protected boolean isCleanupTestDataUsingBulkDelete() {
71-
return true;
72-
}
55+
@RequiresDialectFeature( feature = DialectFeatureChecks.SupportsIdentityColumns.class)
56+
@RequiresDialectFeature( feature = DialectFeatureChecks.CurrentTimestampHasMicrosecondPrecision.class )
57+
@RequiresDialectFeature( feature = DialectFeatureChecks.UsesStandardCurrentTimestampFunction.class )
58+
@DomainModel( annotatedClasses = DefaultGeneratedValueIdentityTest.TheEntity.class )
59+
@SessionFactory
60+
@SuppressWarnings("JUnitMalformedDeclaration")
61+
public class DefaultGeneratedValueIdentityTest {
7362

7463
@Test
75-
@TestForIssue( jiraKey = "HHH-12671" )
76-
public void testGenerationWithIdentityInsert() {
64+
@JiraKey( "HHH-12671" )
65+
public void testGenerationWithIdentityInsert(SessionFactoryScope scope) {
7766
final TheEntity theEntity = new TheEntity();
7867

79-
doInHibernate( this::sessionFactory, session -> {
68+
scope.inTransaction( (session) -> {
8069
assertNull( theEntity.createdDate );
8170
assertNull( theEntity.alwaysDate );
8271
assertNull( theEntity.vmCreatedDate );
@@ -121,7 +110,7 @@ public void testGenerationWithIdentityInsert() {
121110
assertNotNull( theEntity.alwaysDate );
122111
assertEquals( "Bob", theEntity.name );
123112

124-
doInHibernate( this::sessionFactory, session -> {
113+
scope.inTransaction( (session) -> {
125114
TheEntity _theEntity = session.get( TheEntity.class, theEntity.id );
126115
assertNotNull( _theEntity.createdDate );
127116
assertNotNull( _theEntity.alwaysDate );
@@ -145,8 +134,13 @@ public void testGenerationWithIdentityInsert() {
145134
} );
146135
}
147136

137+
@AfterEach
138+
public void dropTestData(SessionFactoryScope scope) {
139+
scope.inTransaction( (s) -> s.createQuery( "delete TheEntity" ).executeUpdate() );
140+
}
141+
148142
@Entity( name = "TheEntity" )
149-
private static class TheEntity {
143+
public static class TheEntity {
150144
@Id
151145
@GeneratedValue(strategy = GenerationType.IDENTITY)
152146
private Integer id;

hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/DefaultGeneratedValueTest.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,20 @@
2525
import org.hibernate.annotations.CreationTimestamp;
2626
import org.hibernate.annotations.Generated;
2727
import org.hibernate.annotations.UpdateTimestamp;
28-
import org.hibernate.dialect.MySQLDialect;
29-
import org.hibernate.dialect.SybaseDialect;
30-
import org.hibernate.dialect.TiDBDialect;
3128
import org.hibernate.generator.EventType;
3229
import org.hibernate.generator.internal.CurrentTimestampGeneration;
3330
import org.hibernate.orm.test.annotations.MutableClock;
3431
import org.hibernate.orm.test.annotations.MutableClockSettingProvider;
3532

33+
34+
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
3635
import org.hibernate.testing.orm.junit.DomainModel;
3736
import org.hibernate.testing.orm.junit.JiraKey;
37+
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
3838
import org.hibernate.testing.orm.junit.ServiceRegistry;
3939
import org.hibernate.testing.orm.junit.SessionFactory;
4040
import org.hibernate.testing.orm.junit.SessionFactoryScope;
4141
import org.hibernate.testing.orm.junit.SettingProvider;
42-
import org.hibernate.testing.orm.junit.SkipForDialect;
4342
import org.junit.jupiter.api.AfterEach;
4443
import org.junit.jupiter.api.BeforeEach;
4544
import org.junit.jupiter.api.Test;
@@ -60,9 +59,8 @@
6059
* @author Steve Ebersole
6160
* @author Gunnar Morling
6261
*/
63-
@SkipForDialect( dialectClass = SybaseDialect.class, matchSubTypes = true, reason = "CURRENT_TIMESTAMP not supported as default value in Sybase" )
64-
@SkipForDialect( dialectClass = MySQLDialect.class, reason = "See HHH-10196" )
65-
@SkipForDialect( dialectClass = TiDBDialect.class, reason = "See HHH-10196" )
62+
@RequiresDialectFeature( feature = DialectFeatureChecks.CurrentTimestampHasMicrosecondPrecision.class )
63+
@RequiresDialectFeature( feature = DialectFeatureChecks.UsesStandardCurrentTimestampFunction.class )
6664
@ServiceRegistry(settingProviders = @SettingProvider(settingName = CurrentTimestampGeneration.CLOCK_SETTING_NAME, provider = MutableClockSettingProvider.class))
6765
@DomainModel( annotatedClasses = DefaultGeneratedValueTest.TheEntity.class )
6866
@SessionFactory

hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/MultipleGeneratedValuesTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
@DomainModel( annotatedClasses = MultipleGeneratedValuesTests.GeneratedInstantEntity.class )
3838
@SessionFactory
3939
@RequiresDialectFeature(feature = DialectFeatureChecks.CurrentTimestampHasMicrosecondPrecision.class, comment = "Without this, we might not see an update to the timestamp")
40-
@SkipForDialect( dialectClass = SybaseASEDialect.class, matchSubTypes = true, reason = "CURRENT_TIMESTAMP not supported in insert/update in Sybase ASE. Also see https://groups.google.com/g/comp.databases.sybase/c/j-RxPnF3img" )
40+
@RequiresDialectFeature( feature = DialectFeatureChecks.UsesStandardCurrentTimestampFunction.class )
4141
@SkipForDialect( dialectClass = SQLServerDialect.class, matchSubTypes = true, reason = "CURRENT_TIMESTAMP has millisecond precision" )
4242
public class MultipleGeneratedValuesTests {
4343
@Test

hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/ProposedGeneratedTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99
import java.time.Instant;
1010

1111
import org.hibernate.HibernateError;
12-
import org.hibernate.dialect.SybaseASEDialect;
1312
import org.hibernate.generator.EventType;
1413

1514
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
1615
import org.hibernate.testing.orm.junit.DomainModel;
1716
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
1817
import org.hibernate.testing.orm.junit.SessionFactory;
1918
import org.hibernate.testing.orm.junit.SessionFactoryScope;
20-
import org.hibernate.testing.orm.junit.SkipForDialect;
2119
import org.junit.jupiter.api.Test;
2220

2321
import jakarta.persistence.Entity;
@@ -34,7 +32,7 @@
3432
@DomainModel( annotatedClasses = ProposedGeneratedTests.GeneratedInstantEntity.class )
3533
@SessionFactory
3634
@RequiresDialectFeature(feature = DialectFeatureChecks.CurrentTimestampHasMicrosecondPrecision.class, comment = "Without this, we might not see an update to the timestamp")
37-
@SkipForDialect( dialectClass = SybaseASEDialect.class, matchSubTypes = true, reason = "CURRENT_TIMESTAMP not supported in insert/update in Sybase ASE. Also see https://groups.google.com/g/comp.databases.sybase/c/j-RxPnF3img" )
35+
@RequiresDialectFeature( feature = DialectFeatureChecks.UsesStandardCurrentTimestampFunction.class )
3836
public class ProposedGeneratedTests {
3937
@Test
4038
public void test(SessionFactoryScope scope) throws InterruptedException {

hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/FunctionTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.hamcrest.Matchers;
1010
import org.hibernate.QueryException;
1111
import org.hibernate.community.dialect.AltibaseDialect;
12+
import org.hibernate.community.dialect.InformixDialect;
1213
import org.hibernate.dialect.CockroachDialect;
1314
import org.hibernate.dialect.DB2Dialect;
1415
import org.hibernate.community.dialect.DerbyDialect;
@@ -568,6 +569,7 @@ public void testRoundTruncFunctions(SessionFactoryScope scope) {
568569

569570
@Test
570571
@SkipForDialect(dialectClass = DerbyDialect.class, reason = "Derby doesn't support any form of date truncation")
572+
@SkipForDialect(dialectClass = InformixDialect.class, reason = "Informix doesn't support any form of date truncation")
571573
public void testDateTruncFunction(SessionFactoryScope scope) {
572574
scope.inTransaction(
573575
session -> {

hibernate-core/src/test/java/org/hibernate/orm/test/temporal/TimestampPropertyTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212

1313
import org.hibernate.annotations.ColumnDefault;
1414
import org.hibernate.annotations.Generated;
15-
import org.hibernate.dialect.MySQLDialect;
16-
import org.hibernate.dialect.SybaseDialect;
1715
import org.hibernate.query.Query;
1816
import org.hibernate.type.StandardBasicTypes;
1917

18+
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
2019
import org.hibernate.testing.orm.junit.DomainModel;
20+
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
2121
import org.hibernate.testing.orm.junit.SessionFactory;
2222
import org.hibernate.testing.orm.junit.SessionFactoryScope;
23-
import org.hibernate.testing.orm.junit.SkipForDialect;
2423
import org.junit.jupiter.api.Test;
2524

2625
import jakarta.persistence.GeneratedValue;
@@ -43,8 +42,8 @@
4342
* @author Gail Badner
4443
*/
4544
@SuppressWarnings("JUnitMalformedDeclaration")
46-
@SkipForDialect(dialectClass = MySQLDialect.class, matchSubTypes = true, reason = "CURRENT_TIMESTAMP not supported as default value in MySQL")
47-
@SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true, reason = "CURRENT_TIMESTAMP not supported as default value in Sybase")
45+
@RequiresDialectFeature(feature = DialectFeatureChecks.CurrentTimestampHasMicrosecondPrecision.class, comment = "Without this, we might not see an update to the timestamp")
46+
@RequiresDialectFeature( feature = DialectFeatureChecks.UsesStandardCurrentTimestampFunction.class )
4847
@DomainModel(
4948
annotatedClasses = TimestampPropertyTest.Entity.class
5049
)

0 commit comments

Comments
 (0)