Skip to content

Commit f83e149

Browse files
committed
Strong Hibernate 5.1 recommendation
Issue: SPR-13480 Issue: SPR-14176 (cherry picked from commit 44a9c49)
1 parent 4c41b9d commit f83e149

File tree

1 file changed

+25
-28
lines changed

1 file changed

+25
-28
lines changed

src/asciidoc/data-access.adoc

+25-28
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,8 @@ the `HibernateTransactionManager` needs a reference to the `SessionFactory`.
334334
[source,xml,indent=0]
335335
[subs="verbatim,quotes"]
336336
----
337-
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
338-
<property name="dataSource" ref="dataSource" />
337+
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
338+
<property name="dataSource" ref="dataSource"/>
339339
<property name="mappingResources">
340340
<list>
341341
<value>org/springframework/samples/petclinic/hibernate/petclinic.hbm.xml</value>
@@ -348,8 +348,8 @@ the `HibernateTransactionManager` needs a reference to the `SessionFactory`.
348348
</property>
349349
</bean>
350350
351-
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
352-
<property name="sessionFactory" ref="sessionFactory" />
351+
<bean id="txManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
352+
<property name="sessionFactory" ref="sessionFactory"/>
353353
</bean>
354354
----
355355

@@ -1296,7 +1296,7 @@ These default settings can be changed; the various properties of the `@Transacti
12961296
annotation are summarized in the following table:
12971297

12981298
[[tx-attransactional-properties]]
1299-
.@
1299+
.@Transactional Settings
13001300
|===
13011301
| Property| Type| Description
13021302

@@ -1778,7 +1778,7 @@ a transaction. You then pass an instance of your custom `TransactionCallback` to
17781778
17791779
// use constructor-injection to supply the PlatformTransactionManager
17801780
public SimpleService(PlatformTransactionManager transactionManager) {
1781-
Assert.notNull(transactionManager, "The ''transactionManager'' argument must not be null.");
1781+
Assert.notNull(transactionManager, "The 'transactionManager' argument must not be null.");
17821782
this.transactionTemplate = new TransactionTemplate(transactionManager);
17831783
}
17841784
@@ -1845,7 +1845,7 @@ a specific `TransactionTemplate:`
18451845
private final TransactionTemplate transactionTemplate;
18461846
18471847
public SimpleService(PlatformTransactionManager transactionManager) {
1848-
Assert.notNull(transactionManager, "The ''transactionManager'' argument must not be null.");
1848+
Assert.notNull(transactionManager, "The 'transactionManager' argument must not be null.");
18491849
this.transactionTemplate = new TransactionTemplate(transactionManager);
18501850
18511851
// the transaction settings can be set here explicitly if so desired
@@ -2074,12 +2074,11 @@ the root exception. These exceptions wrap the original exception so there is nev
20742074
risk that one might lose any information as to what might have gone wrong.
20752075

20762076
In addition to JDBC exceptions, Spring can also wrap Hibernate-specific exceptions,
2077-
converting them from proprietary, checked exceptions (in the case of versions of
2078-
Hibernate prior to Hibernate 3.0), to a set of focused runtime exceptions (the same is
2079-
true for JDO and JPA exceptions). This allows one to handle most persistence exceptions,
2080-
which are non-recoverable, only in the appropriate layers, without having annoying
2081-
boilerplate catch-and-throw blocks and exception declarations in one's DAOs. (One can
2082-
still trap and handle exceptions anywhere one needs to though.) As mentioned above, JDBC
2077+
converting them to a set of focused runtime exceptions (the same is true for JDO and
2078+
JPA exceptions). This allows one to handle most persistence exceptions, which are
2079+
non-recoverable, only in the appropriate layers, without having annoying boilerplate
2080+
catch-and-throw blocks and exception declarations in one's DAOs. (One can still trap
2081+
and handle exceptions anywhere one needs to though.) As mentioned above, JDBC
20832082
exceptions (including database-specific dialects) are also converted to the same
20842083
hierarchy, meaning that one can perform some operations with JDBC within a consistent
20852084
programming model.
@@ -2919,10 +2918,6 @@ query methods, one for an `int` and one that queries for a `String`.
29192918
public String getName() {
29202919
return this.jdbcTemplate.queryForObject("select name from mytable", String.class);
29212920
}
2922-
2923-
public void setDataSource(DataSource dataSource) {
2924-
this.dataSource = dataSource;
2925-
}
29262921
}
29272922
----
29282923

@@ -5107,7 +5102,7 @@ exception hierarchies.
51075102

51085103
[[orm-hibernate]]
51095104
=== Hibernate
5110-
We will start with a coverage of http://www.hibernate.org/[Hibernate 3] in a Spring
5105+
We will start with a coverage of http://www.hibernate.org/[Hibernate 5] in a Spring
51115106
environment, using it to demonstrate the approach that Spring takes towards integrating
51125107
O/R mappers. This section will cover many issues in detail and show different variations
51135108
of DAO implementations and transaction demarcation. Most of these patterns can be
@@ -5116,7 +5111,9 @@ chapter will then cover the other ORM technologies, showing briefer examples the
51165111

51175112
[NOTE]
51185113
====
5119-
As of Spring 4.0, Spring requires Hibernate 3.6 or later.
5114+
As of Spring 4.0, Spring requires Hibernate 3.6 or later. Note that the Hibernate team
5115+
stopped supporting Hibernate 3 years ago and even phased out support for Hibernate 4.x
5116+
in late 2015. We therefore recommend Hibernate 5.1 and higher from a 2016+ perspective.
51205117
====
51215118

51225119

@@ -5145,7 +5142,7 @@ JDBC `DataSource` and a Hibernate `SessionFactory` on top of it:
51455142
<property name="password" value=""/>
51465143
</bean>
51475144
5148-
<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
5145+
<bean id="mySessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
51495146
<property name="dataSource" ref="myDataSource"/>
51505147
<property name="mappingResources">
51515148
<list>
@@ -5181,8 +5178,8 @@ is typically not common outside of an EJB context.
51815178

51825179

51835180
[[orm-hibernate-straight]]
5184-
==== Implementing DAOs based on plain Hibernate 3 API
5185-
Hibernate 3 has a feature called contextual sessions, wherein Hibernate itself manages
5181+
==== Implementing DAOs based on plain Hibernate API
5182+
Hibernate has a feature called contextual sessions, wherein Hibernate itself manages
51865183
one current `Session` per transaction. This is roughly equivalent to Spring's
51875184
synchronization of one Hibernate `Session` per transaction. A corresponding DAO
51885185
implementation resembles the following example, based on the plain Hibernate API:
@@ -5251,7 +5248,7 @@ the return of the current `Session` associated with the ongoing JTA transaction,
52515248
This behavior applies regardless of whether you are using Spring's
52525249
`JtaTransactionManager`, EJB container managed transactions (CMTs), or JTA.
52535250

5254-
In summary: you can implement DAOs based on the plain Hibernate 3 API, while still being
5251+
In summary: you can implement DAOs based on the plain Hibernate API, while still being
52555252
able to participate in Spring-managed transactions.
52565253

52575254

@@ -5296,7 +5293,7 @@ XML, for a simple service class:
52965293
<!-- SessionFactory, DataSource, etc. omitted -->
52975294
52985295
<bean id="transactionManager"
5299-
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
5296+
class="org.springframework.orm.hibernate5.HibernateTransactionManager">
53005297
<property name="sessionFactory" ref="sessionFactory"/>
53015298
</bean>
53025299
@@ -5398,7 +5395,7 @@ provide is the TransactionManager implementation and a "<tx:annotation-driven/>"
53985395
<!-- SessionFactory, DataSource, etc. omitted -->
53995396
54005397
<bean id="transactionManager"
5401-
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
5398+
class="org.springframework.orm.hibernate5.HibernateTransactionManager">
54025399
<property name="sessionFactory" ref="sessionFactory"/>
54035400
</bean>
54045401
@@ -5429,7 +5426,7 @@ and an example for a business method implementation:
54295426
----
54305427
<beans>
54315428
5432-
<bean id="myTxManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
5429+
<bean id="myTxManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
54335430
<property name="sessionFactory" ref="mySessionFactory"/>
54345431
</bean>
54355432
@@ -5509,7 +5506,7 @@ long as it is using `JtaTransactionManager` as the strategy.
55095506
<jee:jndi-lookup id="dataSource2" jndi-name="java:comp/env/jdbc/myds2"/>
55105507
55115508
<bean id="mySessionFactory1"
5512-
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
5509+
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
55135510
<property name="dataSource" ref="myDataSource1"/>
55145511
<property name="mappingResources">
55155512
<list>
@@ -5525,7 +5522,7 @@ long as it is using `JtaTransactionManager` as the strategy.
55255522
</bean>
55265523
55275524
<bean id="mySessionFactory2"
5528-
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
5525+
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
55295526
<property name="dataSource" ref="myDataSource2"/>
55305527
<property name="mappingResources">
55315528
<list>

0 commit comments

Comments
 (0)