Skip to content

Commit 45c9532

Browse files
authored
Merge pull request eugenp#5947 from eelhazati/master
Hibernate 5 bootstrap API Test.
2 parents e290361 + 5996de6 commit 45c9532

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.baeldung.hibernate.bootstrap;
2+
3+
import com.baeldung.hibernate.pojo.Movie;
4+
import org.hibernate.SessionFactory;
5+
import org.hibernate.boot.Metadata;
6+
import org.hibernate.boot.MetadataSources;
7+
import org.hibernate.boot.registry.BootstrapServiceRegistry;
8+
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
9+
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
10+
import org.hibernate.service.ServiceRegistry;
11+
import org.junit.After;
12+
import org.junit.Test;
13+
14+
import java.io.IOException;
15+
16+
import static org.junit.Assert.assertNotNull;
17+
18+
public class BootstrapAPIIntegrationTest {
19+
20+
SessionFactory sessionFactory = null;
21+
22+
@Test
23+
public void whenServiceRegistryAndMetadata_thenSessionFactory() throws IOException {
24+
25+
BootstrapServiceRegistry bootstrapRegistry = new BootstrapServiceRegistryBuilder()
26+
.build();
27+
28+
ServiceRegistry standardRegistry = new StandardServiceRegistryBuilder(bootstrapRegistry)
29+
// No need for hibernate.cfg.xml file, an hibernate.properties is sufficient.
30+
//.configure()
31+
.build();
32+
33+
MetadataSources metadataSources = new MetadataSources(standardRegistry);
34+
metadataSources.addAnnotatedClass(Movie.class);
35+
36+
Metadata metadata = metadataSources.getMetadataBuilder().build();
37+
38+
sessionFactory = metadata.buildSessionFactory();
39+
assertNotNull(sessionFactory);
40+
sessionFactory.close();
41+
}
42+
43+
@After
44+
public void clean() throws IOException {
45+
sessionFactory.close();
46+
}
47+
}

0 commit comments

Comments
 (0)