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:
2026-09-20 06:06:42 +00:00
committed by Claude
commit 8568c0ce6c
330 changed files with 23668 additions and 0 deletions
@@ -0,0 +1,54 @@
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;
/**
* Backs ankurm.com post 4876, docs/13-date-and-time-mapping.md chapter "Second-precision / truncation".
* Default (H2) profile here; see {@link NanosecondTruncationHsqldbTest} for the HSQLDB variant.
*/
@SpringBootTest
class NanosecondTruncationTest {
private static final Logger DEMO = LoggerFactory.getLogger("DEMO");
@Autowired
private EntityManagerFactory emf;
@Test
void nanosecondsOnH2() {
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("H2 2.4.240: original LocalDateTime nanos = {}", withNanos.getNano());
DEMO.info("H2 2.4.240: plain column (precision default) nanos = {} (value={})",
loaded.getPlainLocalDateTime().getNano(), loaded.getPlainLocalDateTime());
DEMO.info("H2 2.4.240: @Column(precision=9) column nanos = {} (value={})",
loaded.getHighPrecisionLocalDateTime().getNano(), loaded.getHighPrecisionLocalDateTime());
DEMO.info("H2 2.4.240: original Instant nanos = {}", instantWithNanos.getNano());
DEMO.info("H2 2.4.240: plain Instant column nanos = {} (value={})",
loaded.getPlainInstant().getNano(), loaded.getPlainInstant());
em2.close();
}
}