Add Hibernate 7 batches 2-6: mapping styles, JPA annotations, natural IDs, @Immutable, stored procedures, in-memory test databases, JNDI mocking, proxies, associations, temporal mapping, named queries, HQL, Criteria API and EntityManager bootstrapping (Hibernate 7.4.5.Final + Spring Boot 4.1.1 + JDK 25)
Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01EQNA6DJ9VgCtW6zhCE8Xud
This commit is contained in:
+46
@@ -0,0 +1,46 @@
|
||||
package com.ankurm.hibernatedemo.mappingstyle;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import com.ankurm.hibernatedemo.HibernateDemoApplication;
|
||||
import org.hibernate.AnnotationException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
/**
|
||||
* <xml-mapping-metadata-complete/> makes Hibernate IGNORE ALL annotations for this
|
||||
* persistence unit -- not just the ones a matching orm.xml entry overrides. OverrideEntity
|
||||
* carries @Id/@GeneratedValue on "id" in Java, but the metadata-complete orm.xml entry only
|
||||
* declares <basic name="value"> and omits <id> entirely. Result: bootstrap fails because
|
||||
* the (ignored) @Id annotation no longer counts -- proving metadata-complete is not just an
|
||||
* override switch, it is a full annotation kill-switch for the persistence unit.
|
||||
*
|
||||
* <p>Docs: docs/04-annotations-vs-xml.md, Topic 1.
|
||||
*/
|
||||
class XmlMappingMetadataCompleteTest {
|
||||
|
||||
@Test
|
||||
void metadataComplete_ignoresAtIdAnnotation_bootFailsWithNoIdentifier() {
|
||||
SpringApplicationBuilder builder = new SpringApplicationBuilder(HibernateDemoApplication.class)
|
||||
.properties("spring.jpa.mapping-resources=orm-xml-metadata-complete.xml");
|
||||
|
||||
BeanCreationException ex = assertThrows(BeanCreationException.class, () -> {
|
||||
try (ConfigurableApplicationContext ctx = builder.run()) {
|
||||
// never reached
|
||||
}
|
||||
});
|
||||
|
||||
Throwable root = ex;
|
||||
while (root.getCause() != null) {
|
||||
root = root.getCause();
|
||||
}
|
||||
System.out.println("RESULT[metadata-complete]: boot FAILED as predicted: " + root.getClass().getName()
|
||||
+ ": " + root.getMessage());
|
||||
assertThat(root).isInstanceOf(AnnotationException.class);
|
||||
assertThat(root.getMessage()).contains("has no identifier");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user