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:
+51
@@ -0,0 +1,51 @@
|
||||
package com.ankurm.hibernatedemo.persistenceannotations;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.ankurm.hibernatedemo.HibernateDemoApplication;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
import java.util.Map;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
/**
|
||||
* Does {@code @JdbcTypeCode(SqlTypes.JSON)} actually work against H2 2.4.240? Honest empirical
|
||||
* check -- if H2 rejects it, this test says so instead of asserting success.
|
||||
*
|
||||
* <p>Docs: docs/05-jpa-persistence-annotations.md, Topic 2.
|
||||
*/
|
||||
@SpringBootTest(classes = HibernateDemoApplication.class)
|
||||
class JsonColumnOnH2Test {
|
||||
|
||||
@Autowired
|
||||
private EntityManagerFactory emf;
|
||||
|
||||
@Test
|
||||
void jdbcTypeCodeJson_onH2_roundTripsAMap() {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
JsonColumnEntity e = new JsonColumnEntity(Map.of("color", "red", "qty", 5));
|
||||
em.persist(e);
|
||||
em.getTransaction().commit();
|
||||
Long id = e.getId();
|
||||
em.close();
|
||||
|
||||
EntityManager em2 = emf.createEntityManager();
|
||||
JsonColumnEntity loaded = em2.find(JsonColumnEntity.class, id);
|
||||
em2.close();
|
||||
|
||||
System.out.println("RESULT[jdbctypecode-json-h2]: persisted+loaded details=" + loaded.getDetails());
|
||||
assertThat(loaded.getDetails()).containsEntry("color", "red");
|
||||
|
||||
// Inspect the actual column type H2 chose for it.
|
||||
EntityManager em3 = emf.createEntityManager();
|
||||
Object colType = em3.createNativeQuery(
|
||||
"select data_type from information_schema.columns "
|
||||
+ "where table_name = 'JSON_COLUMN_ENTITY' and column_name = 'DETAILS'")
|
||||
.getSingleResult();
|
||||
em3.close();
|
||||
System.out.println("RESULT[jdbctypecode-json-h2]: H2 column type for the JSON field = " + colType);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user