HHH-10243 - document package registration for Hibernate 5

(cherry picked from commit 705493d9e8)
This commit is contained in:
Vlad Mihalcea 2016-10-05 17:23:19 +03:00 committed by Gail Badner
parent 747d24b7c1
commit b5356b31e1
1 changed files with 23 additions and 0 deletions

View File

@ -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 {