HHH-10465 - Loss of precision in temporal JavaTypeDescriptor implementations
Test to validate if the Timestamp time handles fraction of a second
This commit is contained in:
parent
877a05213c
commit
50346775b0
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.type;
|
||||
|
||||
import java.sql.Time;
|
||||
import java.sql.Timestamp;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Vlad Mihalcea
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-10465")
|
||||
public class TimeAndTimestampTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Event.class
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
Event event = new Event();
|
||||
event.id = 1L;
|
||||
event.timeValue = new Time( 123 );
|
||||
event.timestampValue = new Timestamp( 456 );
|
||||
|
||||
session.persist( event );
|
||||
} );
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
Event event = session.find( Event.class, 1L );
|
||||
assertEquals(123, event.timeValue.getTime());
|
||||
assertEquals(456, event.timestampValue.getTime());
|
||||
} );
|
||||
}
|
||||
|
||||
@Entity(name = "Event")
|
||||
public static class Event {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
private Time timeValue;
|
||||
|
||||
private Timestamp timestampValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCleanupTestDataRequired() {
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue