@Jaanus 拒绝@Renjith 提供的链接太仓促了
该链接指出它确实在 XML 中工作,但必须作为会话工厂的属性注入,如下面的 XML 代码摘录所示:
<!-- object to relational mapping configuration -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="hibernateProperties">
<property name="map">
<map>
<entry key="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
<entry key="hibernate.hbm2ddl.auto" value="validate" />
<entry key="hibernate.connection.charSet" value="UTF-8" />
<entry key="hibernate.show_sql" value="true" />
<entry key="hibernate.jdbc.batch_size" value="0" />
</map>
</property>
</property>
<property name="namingStrategy">
<bean class="org.hibernate.cfg.ImprovedNamingStrategy" />
</property>
<property name="dataSource" ref="dataSource" />
...
</bean>