Skip to content

Commit 3741ac7

Browse files
committed
added section on JPA EntityManagerFactory bootstrapping without persistence.xml
1 parent d5b9b26 commit 3741ac7

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

spring-framework-reference/src/new-in-3.1.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,20 @@
181181
</listitem>
182182
</itemizedlist>
183183
</section>
184+
<section>
185+
<title>JPA EntityManagerFactory bootstrapping without persistence.xml</title>
186+
<para>In standard JPA, persistence units get defined through <literal>META-INF/persistence.xml</literal>
187+
files in specific jar files which will in turn get searched for <literal>@Entity</literal> classes.
188+
In many cases, persistence.xml does not contain more than a unit name and relies on defaults and/or
189+
external setup for all other concerns (such as the DataSource to use, etc). For that reason, Spring 3.1
190+
provides an alternative: <classname>LocalContainerEntityManagerFactoryBean</classname> accepts a
191+
'packagesToScan' property, specifying base packages to scan for <literal>@Entity</literal> classes.
192+
This is analogous to <classname>AnnotationSessionFactoryBean</classname>'s property of the same name
193+
for native Hibernate setup, and also to Spring's component-scan feature for regular Spring beans.
194+
Effectively, this allows for XML-free JPA setup at the mere expense of specifying a base package for
195+
entity scanning: a particularly fine match for Spring applications which rely on component scanning
196+
for Spring beans as well, possibly even bootstrapped using a code-based Servlet 3.0 initializer.</para>
197+
</section>
184198
<section>
185199
<title>New HandlerMethod-based Support Classes For Annotated Controller Processing</title>
186200
<para>Spring 3.1 introduces a new set of support classes for processing requests

0 commit comments

Comments
 (0)