From 493808ddc14d93817dd4306c1f015f0fbb772742 Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Wed, 17 Dec 2014 23:21:51 -0800 Subject: [PATCH] HHH-8401 : Unit test fixes (cherry picked from commit 45511f10ae58e9460fd09e6da5c33b1332494cbf) --- .../org/hibernate/test/hql/Department.java | 2 +- .../java/org/hibernate/test/hql/Employee.java | 2 +- .../java/org/hibernate/test/hql/Title.java | 2 +- .../test/temporal/TimePropertyTest.java | 7 +++ .../test/temporal/TimestampPropertyTest.java | 54 ------------------- .../ValidityAuditStrategyRevEndTsTest.java | 5 +- 6 files changed, 14 insertions(+), 58 deletions(-) diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/Department.java b/hibernate-core/src/test/java/org/hibernate/test/hql/Department.java index 491e7d8d45..d8691604b4 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/Department.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hql/Department.java @@ -37,7 +37,7 @@ public class Department implements java.io.Serializable { private String deptName; @Id - @GeneratedValue(strategy=GenerationType.IDENTITY) + @GeneratedValue @Column(name="id_dep") public Integer getDeptNo() { return this.deptNo; diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/Employee.java b/hibernate-core/src/test/java/org/hibernate/test/hql/Employee.java index b3e689a2ca..0eb53b8df9 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/Employee.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hql/Employee.java @@ -41,7 +41,7 @@ import javax.persistence.Table; public class Employee implements Serializable { @Id - @GeneratedValue(strategy=GenerationType.IDENTITY) + @GeneratedValue @Column(name="id_emp") private Integer id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/Title.java b/hibernate-core/src/test/java/org/hibernate/test/hql/Title.java index 146ab438a2..d8d01a1e80 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/Title.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hql/Title.java @@ -37,7 +37,7 @@ import javax.persistence.Table; public class Title implements Serializable { @Id - @GeneratedValue(strategy=GenerationType.IDENTITY) + @GeneratedValue @Column(name="id_title") private Integer id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/temporal/TimePropertyTest.java b/hibernate-core/src/test/java/org/hibernate/test/temporal/TimePropertyTest.java index 01c1afac2c..393f7df526 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/temporal/TimePropertyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/temporal/TimePropertyTest.java @@ -69,6 +69,13 @@ public class TimePropertyTest extends BaseCoreFunctionalTestCase { s.getTransaction().commit(); s.close(); + s = openSession(); + s.getTransaction().begin(); + final Query queryWithParameter = s.createQuery( "from TimePropertyTest$Entity where tAsDate=?" ).setParameter( 0, eOrig.tAsDate ); + final Entity eQueriedWithParameter = (Entity) queryWithParameter.uniqueResult(); + assertNotNull( eQueriedWithParameter ); + s.getTransaction().commit(); + s.close(); s = openSession(); s.getTransaction().begin(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/temporal/TimestampPropertyTest.java b/hibernate-core/src/test/java/org/hibernate/test/temporal/TimestampPropertyTest.java index d5bc14df9b..09fb8519f5 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/temporal/TimestampPropertyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/temporal/TimestampPropertyTest.java @@ -151,55 +151,6 @@ public class TimestampPropertyTest extends BaseCoreFunctionalTestCase { s.close(); } - @Test - public void testTimeGeneratedByColumnDefinition() { - final Entity eOrig = new Entity(); - - Session s = openSession(); - s.getTransaction().begin(); - s.persist( eOrig ); - s.getTransaction().commit(); - s.close(); - - assertNotNull( eOrig.tsColumnDefinition ); - - s = openSession(); - s.getTransaction().begin(); - final Entity eGotten = (Entity) s.get( Entity.class, eOrig.id ); - final String tsColumnDefinitionOrigFormatted = timestampFormat.format( eOrig.tsColumnDefinition ); - final String tsColumnDefinitionGottenFormatted = timestampFormat.format( eGotten.tsColumnDefinition ); - assertEquals( tsColumnDefinitionOrigFormatted , tsColumnDefinitionGottenFormatted ); - s.getTransaction().commit(); - s.close(); - - s = openSession(); - s.getTransaction().begin(); - final Query queryWithParameter = - s.createQuery( "from TimestampPropertyTest$Entity where tsColumnDefinition=?" ) - .setParameter( 0, eOrig.tsColumnDefinition ); - final Entity eQueriedWithParameter = (Entity) queryWithParameter.uniqueResult(); - assertNotNull( eQueriedWithParameter ); - s.getTransaction().commit(); - s.close(); - - s = openSession(); - s.getTransaction().begin(); - final Query queryWithTimestamp = - s.createQuery( "from TimestampPropertyTest$Entity where tsColumnDefinition=?" ) - .setTimestamp( 0, eOrig.tsColumnDefinition ); - final Entity eQueriedWithTimestamp = (Entity) queryWithTimestamp.uniqueResult(); - assertNotNull( eQueriedWithTimestamp ); - s.getTransaction().commit(); - s.close(); - - s = openSession(); - s.getTransaction().begin(); - s.delete( eQueriedWithTimestamp ); - s.getTransaction().commit(); - s.close(); - } - - @Override protected Class[] getAnnotatedClasses() { return new Class[] { Entity.class }; @@ -218,10 +169,5 @@ public class TimestampPropertyTest extends BaseCoreFunctionalTestCase { @Generated( value = GenerationTime.INSERT ) @ColumnDefault( value = "CURRENT_TIMESTAMP" ) private Date tsColumnDefault; - - @Temporal( value = TemporalType.TIMESTAMP ) - @Generated( value = GenerationTime.INSERT ) - @Column( columnDefinition = "datetime(6) default NOW(6)" ) - private Date tsColumnDefinition; } } diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/strategy/ValidityAuditStrategyRevEndTsTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/strategy/ValidityAuditStrategyRevEndTsTest.java index 95491e1cda..76a440043d 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/strategy/ValidityAuditStrategyRevEndTsTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/strategy/ValidityAuditStrategyRevEndTsTest.java @@ -34,6 +34,7 @@ import java.util.Map; import java.util.Set; import org.hibernate.Session; +import org.hibernate.dialect.MySQL57InnoDBDialect; import org.hibernate.dialect.MySQL5Dialect; import org.hibernate.dialect.SybaseASE15Dialect; import org.hibernate.envers.configuration.EnversSettings; @@ -490,8 +491,10 @@ public class ValidityAuditStrategyRevEndTsTest extends BaseEnversJPAFunctionalTe Assert.assertNull( revEnd ); } else { - if ( getDialect() instanceof MySQL5Dialect ) { + if ( getDialect() instanceof MySQL5Dialect && !( getDialect() instanceof MySQL57InnoDBDialect) ) { // MySQL5 DATETIME column type does not contain milliseconds. + // MySQL 5.7 supports milliseconds and when MySQL57InnoDBDialect is used, it is assumed that + // the column is defined as DATETIME(6). Assert.assertEquals( revendTimestamp.getTime(), (revEnd.getTimestamp() - (revEnd.getTimestamp() % 1000))