From b5356b31e1ecc26cadeeb3fef05acfd83bf633b5 Mon Sep 17 00:00:00 2001 From: Vlad Mihalcea Date: Wed, 5 Oct 2016 17:23:19 +0300 Subject: [PATCH] HHH-10243 - document package registration for Hibernate 5 (cherry picked from commit 705493d9e8d26ae29aa2298ec49b81eb463c4824) --- .../userguide/bootstrap/BootstrapTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/documentation/src/test/java/org/hibernate/userguide/bootstrap/BootstrapTest.java b/documentation/src/test/java/org/hibernate/userguide/bootstrap/BootstrapTest.java index faf97239f0..f20bbf912f 100644 --- a/documentation/src/test/java/org/hibernate/userguide/bootstrap/BootstrapTest.java +++ b/documentation/src/test/java/org/hibernate/userguide/bootstrap/BootstrapTest.java @@ -6,6 +6,7 @@ */ package org.hibernate.userguide.bootstrap; +import java.io.File; import java.net.URL; import java.util.ArrayList; import java.util.Collections; @@ -127,6 +128,12 @@ public class BootstrapTest { // important if using runtime bytecode-enhancement sources.addAnnotatedClassName( "org.hibernate.example.Customer" ); + // Read package-level metadata. + sources.addPackage( "hibernate.example" ); + + // Read package-level metadata. + sources.addPackage( MyEntity.class.getPackage() ); + // Adds the named hbm.xml resource as a source: which performs the // classpath lookup and parses the XML sources.addResource( "org/hibernate/example/Order.hbm.xml" ); @@ -134,6 +141,21 @@ public class BootstrapTest { // Adds the named JPA orm.xml resource as a source: which performs the // classpath lookup and parses the XML sources.addResource( "org/hibernate/example/Product.orm.xml" ); + + // Read all mapping documents from a directory tree. + // Assumes that any file named *.hbm.xml is a mapping document. + sources.addDirectory( new File( ".") ); + + // Read mappings from a particular XML file + sources.addFile( new File( "./mapping.xml") ); + + // Read all mappings from a jar file. + // Assumes that any file named *.hbm.xml is a mapping document. + sources.addJar( new File( "./entities.jar") ); + + // Read a mapping as an application resource using the convention that a class named foo.bar.MyEntity is + // mapped by a file named foo/bar/MyEntity.hbm.xml which can be resolved as a classpath resource. + sources.addClass( MyEntity.class ); //end::bootstrap-bootstrap-native-registry-MetadataSources-example[] } catch (Exception ignore) { @@ -141,6 +163,7 @@ public class BootstrapTest { } } + @Test public void test_bootstrap_bootstrap_native_metadata_source_example() { try {