Add Hibernate 7 batches 2-6, batch 7, and batch 8: mapping styles, JPA annotations, natural IDs, @Immutable, stored procedures, in-memory test databases, JNDI mocking, proxies, associations, temporal mapping, named queries, HQL, Criteria API, EntityManager bootstrapping, Ehcache 3 L2 cache configuration, HikariCP connection pooling, Hibernate Validator CDI integration, aggregate functions, sorting, pagination, interceptors, and Hibernate Search 8 (Hibernate 7.4.5.Final + Spring Boot 4.1.1 + JDK 25)
This commit is contained in:
+62
@@ -0,0 +1,62 @@
|
||||
package com.ankurm.hibernatedemo.datetime;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
/**
|
||||
* Same experiment as {@link NanosecondTruncationTest} but against HSQLDB 2.7.3 in-memory,
|
||||
* to see whether the microsecond rounding is H2-specific or shared. Docs: 13-date-and-time-mapping.md.
|
||||
*/
|
||||
@SpringBootTest
|
||||
@TestPropertySource(properties = {
|
||||
"spring.datasource.url=jdbc:hsqldb:mem:nanotest;shutdown=true",
|
||||
"spring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver",
|
||||
"spring.datasource.username=SA",
|
||||
"spring.datasource.password=",
|
||||
"spring.jpa.database-platform=org.hibernate.dialect.HSQLDialect"
|
||||
})
|
||||
class NanosecondTruncationHsqldbTest {
|
||||
|
||||
private static final Logger DEMO = LoggerFactory.getLogger("DEMO");
|
||||
|
||||
@Autowired
|
||||
private EntityManagerFactory emf;
|
||||
|
||||
@Test
|
||||
void nanosecondsOnHsqldb() {
|
||||
LocalDateTime withNanos = LocalDateTime.of(2026, 1, 1, 12, 0, 0, 123_456_789);
|
||||
Instant instantWithNanos = Instant.ofEpochSecond(1_800_000_000L, 123_456_789);
|
||||
|
||||
EntityManager em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
NanoPrecisionEntity e = new NanoPrecisionEntity();
|
||||
e.setPlainLocalDateTime(withNanos);
|
||||
e.setHighPrecisionLocalDateTime(withNanos);
|
||||
e.setPlainInstant(instantWithNanos);
|
||||
em.persist(e);
|
||||
em.getTransaction().commit();
|
||||
Long id = e.getId();
|
||||
em.close();
|
||||
|
||||
EntityManager em2 = emf.createEntityManager();
|
||||
NanoPrecisionEntity loaded = em2.find(NanoPrecisionEntity.class, id);
|
||||
|
||||
DEMO.info("HSQLDB 2.7.3: original LocalDateTime nanos = {}", withNanos.getNano());
|
||||
DEMO.info("HSQLDB 2.7.3: plain column (precision default) nanos = {} (value={})",
|
||||
loaded.getPlainLocalDateTime().getNano(), loaded.getPlainLocalDateTime());
|
||||
DEMO.info("HSQLDB 2.7.3: @Column(precision=9) column nanos = {} (value={})",
|
||||
loaded.getHighPrecisionLocalDateTime().getNano(), loaded.getHighPrecisionLocalDateTime());
|
||||
DEMO.info("HSQLDB 2.7.3: original Instant nanos = {}", instantWithNanos.getNano());
|
||||
DEMO.info("HSQLDB 2.7.3: plain Instant column nanos = {} (value={})",
|
||||
loaded.getPlainInstant().getNano(), loaded.getPlainInstant());
|
||||
em2.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user