Skip to content

Commit 2fbdd53

Browse files
ctapobepodrotbohm
authored andcommitted
DATAJPA-993 - Improved example of infrastructure setup in reference documentation.
Previously EntityManagerFactory was created manually which resulted in LocalContainerEntityManagerFactoryBean not being exposed to ApplicationContext. The latter is an important bean since it enables exception translation. Original pull request: #180.
1 parent 1477c18 commit 2fbdd53

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/main/asciidoc/jpa.adoc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class ApplicationConfig {
6565
}
6666
6767
@Bean
68-
public EntityManagerFactory entityManagerFactory() {
68+
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
6969
7070
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
7171
vendorAdapter.setGenerateDdl(true);
@@ -74,9 +74,7 @@ class ApplicationConfig {
7474
factory.setJpaVendorAdapter(vendorAdapter);
7575
factory.setPackagesToScan("com.acme.domain");
7676
factory.setDataSource(dataSource());
77-
factory.afterPropertiesSet();
78-
79-
return factory.getObject();
77+
return factory;
8078
}
8179
8280
@Bean
@@ -89,6 +87,7 @@ class ApplicationConfig {
8987
}
9088
----
9189
====
90+
NB: It's important to create `LocalContainerEntityManagerFactoryBean` and not `EntityManagerFactory` directly since the former also participates in exception translation mechanisms besides simply creating `EntityManagerFactory`.
9291

9392
The just shown configuration class sets up an embedded HSQL database using the `EmbeddedDatabaseBuilder` API of spring-jdbc. We then set up a `EntityManagerFactory` and use Hibernate as sample persistence provider. The last infrastructure component declared here is the `JpaTransactionManager`. We finally activate Spring Data JPA repositories using the `@EnableJpaRepositories` annotation which essentially carries the same attributes as the XML namespace does. If no base package is configured it will use the one the configuration class resides in.
9493

0 commit comments

Comments
 (0)