Merge pull request #5947 from eelhazati/master
Hibernate 5 bootstrap API Test.
This commit is contained in:
commit
45c9532cfb
|
@ -0,0 +1,47 @@
|
||||||
|
package com.baeldung.hibernate.bootstrap;
|
||||||
|
|
||||||
|
import com.baeldung.hibernate.pojo.Movie;
|
||||||
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.hibernate.boot.Metadata;
|
||||||
|
import org.hibernate.boot.MetadataSources;
|
||||||
|
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
||||||
|
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
|
import org.hibernate.service.ServiceRegistry;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
public class BootstrapAPIIntegrationTest {
|
||||||
|
|
||||||
|
SessionFactory sessionFactory = null;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenServiceRegistryAndMetadata_thenSessionFactory() throws IOException {
|
||||||
|
|
||||||
|
BootstrapServiceRegistry bootstrapRegistry = new BootstrapServiceRegistryBuilder()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
ServiceRegistry standardRegistry = new StandardServiceRegistryBuilder(bootstrapRegistry)
|
||||||
|
// No need for hibernate.cfg.xml file, an hibernate.properties is sufficient.
|
||||||
|
//.configure()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
MetadataSources metadataSources = new MetadataSources(standardRegistry);
|
||||||
|
metadataSources.addAnnotatedClass(Movie.class);
|
||||||
|
|
||||||
|
Metadata metadata = metadataSources.getMetadataBuilder().build();
|
||||||
|
|
||||||
|
sessionFactory = metadata.buildSessionFactory();
|
||||||
|
assertNotNull(sessionFactory);
|
||||||
|
sessionFactory.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void clean() throws IOException {
|
||||||
|
sessionFactory.close();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue