diff --git a/spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/LocalSessionFactoryBean.java b/spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/LocalSessionFactoryBean.java index f2814150087..3f9096d605b 100644 --- a/spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/LocalSessionFactoryBean.java +++ b/spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/LocalSessionFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -126,7 +126,7 @@ public class LocalSessionFactoryBean extends HibernateExceptionTranslator * resources are specified locally via this bean. * @see org.hibernate.cfg.Configuration#configure(java.net.URL) */ - public void setConfigLocations(Resource[] configLocations) { + public void setConfigLocations(Resource... configLocations) { this.configLocations = configLocations; } @@ -140,7 +140,7 @@ public class LocalSessionFactoryBean extends HibernateExceptionTranslator * @see #setMappingLocations * @see org.hibernate.cfg.Configuration#addResource */ - public void setMappingResources(String[] mappingResources) { + public void setMappingResources(String... mappingResources) { this.mappingResources = mappingResources; } @@ -153,7 +153,7 @@ public class LocalSessionFactoryBean extends HibernateExceptionTranslator * or to specify all mappings locally. * @see org.hibernate.cfg.Configuration#addInputStream */ - public void setMappingLocations(Resource[] mappingLocations) { + public void setMappingLocations(Resource... mappingLocations) { this.mappingLocations = mappingLocations; } @@ -166,7 +166,7 @@ public class LocalSessionFactoryBean extends HibernateExceptionTranslator * or to specify all mappings locally. * @see org.hibernate.cfg.Configuration#addCacheableFile(java.io.File) */ - public void setCacheableMappingLocations(Resource[] cacheableMappingLocations) { + public void setCacheableMappingLocations(Resource... cacheableMappingLocations) { this.cacheableMappingLocations = cacheableMappingLocations; } @@ -177,7 +177,7 @@ public class LocalSessionFactoryBean extends HibernateExceptionTranslator * or to specify all mappings locally. * @see org.hibernate.cfg.Configuration#addJar(java.io.File) */ - public void setMappingJarLocations(Resource[] mappingJarLocations) { + public void setMappingJarLocations(Resource... mappingJarLocations) { this.mappingJarLocations = mappingJarLocations; } @@ -188,7 +188,7 @@ public class LocalSessionFactoryBean extends HibernateExceptionTranslator * or to specify all mappings locally. * @see org.hibernate.cfg.Configuration#addDirectory(java.io.File) */ - public void setMappingDirectoryLocations(Resource[] mappingDirectoryLocations) { + public void setMappingDirectoryLocations(Resource... mappingDirectoryLocations) { this.mappingDirectoryLocations = mappingDirectoryLocations; } @@ -237,7 +237,7 @@ public class LocalSessionFactoryBean extends HibernateExceptionTranslator * Specify annotated entity classes to register with this Hibernate SessionFactory. * @see org.hibernate.cfg.Configuration#addAnnotatedClass(Class) */ - public void setAnnotatedClasses(Class[] annotatedClasses) { + public void setAnnotatedClasses(Class... annotatedClasses) { this.annotatedClasses = annotatedClasses; } @@ -246,7 +246,7 @@ public class LocalSessionFactoryBean extends HibernateExceptionTranslator * annotation metadata will be read. * @see org.hibernate.cfg.Configuration#addPackage(String) */ - public void setAnnotatedPackages(String[] annotatedPackages) { + public void setAnnotatedPackages(String... annotatedPackages) { this.annotatedPackages = annotatedPackages; } diff --git a/spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/support/OpenSessionInViewInterceptor.java b/spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/support/OpenSessionInViewInterceptor.java index f3e4ade5939..6a2a1f1e2dd 100644 --- a/spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/support/OpenSessionInViewInterceptor.java +++ b/spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/support/OpenSessionInViewInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,14 +16,13 @@ package org.springframework.orm.hibernate4.support; -import java.util.concurrent.Callable; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.FlushMode; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.SessionFactory; + import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessResourceFailureException; import org.springframework.orm.hibernate4.SessionFactoryUtils; @@ -31,9 +30,9 @@ import org.springframework.orm.hibernate4.SessionHolder; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.ui.ModelMap; import org.springframework.web.context.request.AsyncWebRequestInterceptor; -import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.context.request.WebRequest; -import org.springframework.web.context.request.async.*; +import org.springframework.web.context.request.async.WebAsyncManager; +import org.springframework.web.context.request.async.WebAsyncUtils; /** * Spring web request interceptor that binds a Hibernate {@code Session} to the @@ -79,22 +78,28 @@ public class OpenSessionInViewInterceptor implements AsyncWebRequestInterceptor private SessionFactory sessionFactory; + /** + * Set the Hibernate SessionFactory that should be used to create + * Hibernate Sessions. + */ public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } + /** + * Return the Hibernate SessionFactory that should be used to create + * Hibernate Sessions. + */ public SessionFactory getSessionFactory() { return this.sessionFactory; } /** - * Open a new Hibernate {@code Session} according to the settings of this - * {@code HibernateAccessor} and bind it to the thread via the + * Open a new Hibernate {@code Session} according and bind it to the thread via the * {@link org.springframework.transaction.support.TransactionSynchronizationManager}. */ public void preHandle(WebRequest request) throws DataAccessException { - String participateAttributeName = getParticipateAttributeName(); WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request); diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateAccessor.java b/spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateAccessor.java index ddc08aed8be..bfb35be672d 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateAccessor.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateAccessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -289,7 +289,7 @@ public abstract class HibernateAccessor implements InitializingBean, BeanFactory * @see org.hibernate.Session#enableFilter(String) * @see LocalSessionFactoryBean#setFilterDefinitions */ - public void setFilterNames(String[] filterNames) { + public void setFilterNames(String... filterNames) { this.filterNames = filterNames; } @@ -464,8 +464,8 @@ public abstract class HibernateAccessor implements InitializingBean, BeanFactory protected void enableFilters(Session session) { String[] filterNames = getFilterNames(); if (filterNames != null) { - for (int i = 0; i < filterNames.length; i++) { - session.enableFilter(filterNames[i]); + for (String filterName : filterNames) { + session.enableFilter(filterName); } } } @@ -479,8 +479,8 @@ public abstract class HibernateAccessor implements InitializingBean, BeanFactory protected void disableFilters(Session session) { String[] filterNames = getFilterNames(); if (filterNames != null) { - for (int i = 0; i < filterNames.length; i++) { - session.disableFilter(filterNames[i]); + for (String filterName : filterNames) { + session.disableFilter(filterName); } } } diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateInterceptor.java b/spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateInterceptor.java index 79339de558f..6996a384b88 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateInterceptor.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,7 +36,7 @@ import org.springframework.transaction.support.TransactionSynchronizationManager * Hibernate's own {@code SessionFactory.getCurrentSession()} method, to be * able to detect a thread-bound Session. Typically, the code will look like as follows: * - *
+ * 
  * public void doSomeDataAccessAction() {
  *   Session session = this.sessionFactory.getCurrentSession();
  *   ...
@@ -68,7 +68,12 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
  * @see org.hibernate.SessionFactory#getCurrentSession()
  * @see HibernateTransactionManager
  * @see HibernateTemplate
+ * @deprecated as of Spring 3.2.7, in favor of either HibernateTemplate usage or
+ * native Hibernate API usage within transactions, in combination with a general
+ * {@link org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor}.
+ * Note: This class does not have an equivalent replacement in {@code orm.hibernate4}.
  */
+@Deprecated
 public class HibernateInterceptor extends HibernateAccessor implements MethodInterceptor {
 
 	private boolean exceptionConversionEnabled = true;
diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateOperations.java b/spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateOperations.java
index 3d142f2256d..4292ba8ab7a 100644
--- a/spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateOperations.java
+++ b/spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateOperations.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2014 the original author or authors.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -90,10 +90,13 @@ public interface HibernateOperations {
 	 * {@link List}.
 	 * 

This is a convenience method for executing Hibernate find calls or * queries within an action. - * @param action calback object that specifies the Hibernate action + * @param action callback object that specifies the Hibernate action * @return a List result returned by the action, or {@code null} * @throws org.springframework.dao.DataAccessException in case of Hibernate errors + * @deprecated as of Spring 3.2.7, in favor of using a regular {@link #execute} + * call with a generic List type declared */ + @Deprecated List executeFind(HibernateCallback action) throws DataAccessException; @@ -131,8 +134,7 @@ public interface HibernateOperations { * @throws org.springframework.dao.DataAccessException in case of Hibernate errors * @see org.hibernate.Session#get(Class, java.io.Serializable, org.hibernate.LockMode) */ - T get(Class entityClass, Serializable id, LockMode lockMode) - throws DataAccessException; + T get(Class entityClass, Serializable id, LockMode lockMode) throws DataAccessException; /** * Return the persistent instance of the given entity class @@ -164,8 +166,7 @@ public interface HibernateOperations { * @throws org.springframework.dao.DataAccessException in case of Hibernate errors * @see org.hibernate.Session#get(Class, java.io.Serializable, org.hibernate.LockMode) */ - Object get(String entityName, Serializable id, LockMode lockMode) - throws DataAccessException; + Object get(String entityName, Serializable id, LockMode lockMode) throws DataAccessException; /** * Return the persistent instance of the given entity class @@ -199,8 +200,7 @@ public interface HibernateOperations { * @throws org.springframework.dao.DataAccessException in case of Hibernate errors * @see org.hibernate.Session#load(Class, java.io.Serializable) */ - T load(Class entityClass, Serializable id, LockMode lockMode) - throws DataAccessException; + T load(Class entityClass, Serializable id, LockMode lockMode) throws DataAccessException; /** * Return the persistent instance of the given entity class @@ -234,8 +234,7 @@ public interface HibernateOperations { * @throws org.springframework.dao.DataAccessException in case of Hibernate errors * @see org.hibernate.Session#load(Class, java.io.Serializable) */ - Object load(String entityName, Serializable id, LockMode lockMode) - throws DataAccessException; + Object load(String entityName, Serializable id, LockMode lockMode) throws DataAccessException; /** * Return all persistent instances of the given entity class. @@ -245,7 +244,7 @@ public interface HibernateOperations { * @throws org.springframework.dao.DataAccessException if there is a Hibernate error * @see org.hibernate.Session#createCriteria */ - List loadAll(Class entityClass) throws DataAccessException; + List loadAll(Class entityClass) throws DataAccessException; /** * Load the persistent instance with the given identifier diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateTemplate.java b/spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateTemplate.java index 1edc733d3bd..c656fe694ff 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateTemplate.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -132,7 +132,7 @@ public class HibernateTemplate extends HibernateAccessor implements HibernateOpe /** * Create a new HibernateTemplate instance. - * @param sessionFactory SessionFactory to create Sessions + * @param sessionFactory the SessionFactory to create Sessions with */ public HibernateTemplate(SessionFactory sessionFactory) { setSessionFactory(sessionFactory); @@ -141,7 +141,7 @@ public class HibernateTemplate extends HibernateAccessor implements HibernateOpe /** * Create a new HibernateTemplate instance. - * @param sessionFactory SessionFactory to create Sessions + * @param sessionFactory the SessionFactory to create Sessions with * @param allowCreate if a non-transactional Session should be created when no * transactional Session can be found for the current thread */ @@ -339,6 +339,7 @@ public class HibernateTemplate extends HibernateAccessor implements HibernateOpe return doExecute(action, false, false); } + @Deprecated public List executeFind(HibernateCallback action) throws DataAccessException { Object result = doExecute(action, false, false); if (result != null && !(result instanceof List)) { @@ -480,17 +481,17 @@ public class HibernateTemplate extends HibernateAccessor implements HibernateOpe * @see #prepareCriteria */ protected Session createSessionProxy(Session session) { - Class[] sessionIfcs = null; - Class mainIfc = (session instanceof org.hibernate.classic.Session ? + Class[] sessionIfcs; + Class mainIfc = (session instanceof org.hibernate.classic.Session ? org.hibernate.classic.Session.class : Session.class); if (session instanceof EventSource) { - sessionIfcs = new Class[] {mainIfc, EventSource.class}; + sessionIfcs = new Class[] {mainIfc, EventSource.class}; } else if (session instanceof SessionImplementor) { - sessionIfcs = new Class[] {mainIfc, SessionImplementor.class}; + sessionIfcs = new Class[] {mainIfc, SessionImplementor.class}; } else { - sessionIfcs = new Class[] {mainIfc}; + sessionIfcs = new Class[] {mainIfc}; } return (Session) Proxy.newProxyInstance( session.getClass().getClassLoader(), sessionIfcs, diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate3/LocalSessionFactoryBean.java b/spring-orm/src/main/java/org/springframework/orm/hibernate3/LocalSessionFactoryBean.java index 9310853b6e8..6c87f056ce5 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate3/LocalSessionFactoryBean.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate3/LocalSessionFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -276,7 +276,7 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen * resources are specified locally via this bean. * @see org.hibernate.cfg.Configuration#configure(java.net.URL) */ - public void setConfigLocations(Resource[] configLocations) { + public void setConfigLocations(Resource... configLocations) { this.configLocations = configLocations; } @@ -290,7 +290,7 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen * @see #setMappingLocations * @see org.hibernate.cfg.Configuration#addResource */ - public void setMappingResources(String[] mappingResources) { + public void setMappingResources(String... mappingResources) { this.mappingResources = mappingResources; } @@ -303,7 +303,7 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen * or to specify all mappings locally. * @see org.hibernate.cfg.Configuration#addInputStream */ - public void setMappingLocations(Resource[] mappingLocations) { + public void setMappingLocations(Resource... mappingLocations) { this.mappingLocations = mappingLocations; } @@ -316,7 +316,7 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen * or to specify all mappings locally. * @see org.hibernate.cfg.Configuration#addCacheableFile(java.io.File) */ - public void setCacheableMappingLocations(Resource[] cacheableMappingLocations) { + public void setCacheableMappingLocations(Resource... cacheableMappingLocations) { this.cacheableMappingLocations = cacheableMappingLocations; } @@ -327,7 +327,7 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen * or to specify all mappings locally. * @see org.hibernate.cfg.Configuration#addJar(java.io.File) */ - public void setMappingJarLocations(Resource[] mappingJarLocations) { + public void setMappingJarLocations(Resource... mappingJarLocations) { this.mappingJarLocations = mappingJarLocations; } @@ -338,7 +338,7 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen * or to specify all mappings locally. * @see org.hibernate.cfg.Configuration#addDirectory(java.io.File) */ - public void setMappingDirectoryLocations(Resource[] mappingDirectoryLocations) { + public void setMappingDirectoryLocations(Resource... mappingDirectoryLocations) { this.mappingDirectoryLocations = mappingDirectoryLocations; } @@ -456,7 +456,7 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen * @see TypeDefinitionBean * @see org.hibernate.cfg.Mappings#addTypeDef(String, String, java.util.Properties) */ - public void setTypeDefinitions(TypeDefinitionBean[] typeDefinitions) { + public void setTypeDefinitions(TypeDefinitionBean... typeDefinitions) { this.typeDefinitions = typeDefinitions; } @@ -470,7 +470,7 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen * @see FilterDefinitionFactoryBean * @see org.hibernate.cfg.Configuration#addFilterDefinition */ - public void setFilterDefinitions(FilterDefinition[] filterDefinitions) { + public void setFilterDefinitions(FilterDefinition... filterDefinitions) { this.filterDefinitions = filterDefinitions; } diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate3/SessionFactoryUtils.java b/spring-orm/src/main/java/org/springframework/orm/hibernate3/SessionFactoryUtils.java index a6e13b673da..e1a26d39efb 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate3/SessionFactoryUtils.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate3/SessionFactoryUtils.java @@ -611,10 +611,12 @@ public abstract class SessionFactoryUtils { */ public static void applyTransactionTimeout(Criteria criteria, SessionFactory sessionFactory) { Assert.notNull(criteria, "No Criteria object specified"); - SessionHolder sessionHolder = - (SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory); - if (sessionHolder != null && sessionHolder.hasTimeout()) { - criteria.setTimeout(sessionHolder.getTimeToLiveInSeconds()); + if (sessionFactory != null) { + SessionHolder sessionHolder = + (SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory); + if (sessionHolder != null && sessionHolder.hasTimeout()) { + criteria.setTimeout(sessionHolder.getTimeToLiveInSeconds()); + } } } diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate3/annotation/AnnotationSessionFactoryBean.java b/spring-orm/src/main/java/org/springframework/orm/hibernate3/annotation/AnnotationSessionFactoryBean.java index 72f5ee42ea7..ab2d1d460cd 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate3/annotation/AnnotationSessionFactoryBean.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate3/annotation/AnnotationSessionFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,10 +42,7 @@ import org.springframework.util.ClassUtils; /** * Subclass of Spring's standard LocalSessionFactoryBean for Hibernate, - * supporting JDK 1.5+ annotation metadata for mappings. - * - *

Note: This class requires Hibernate 3.2 or later, with the - * Java Persistence API and the Hibernate Annotations add-on present. + * supporting annotation metadata for mappings. * *

Example for an AnnotationSessionFactoryBean bean definition: * @@ -68,6 +65,9 @@ import org.springframework.util.ClassUtils; * <property name="packagesToScan" value="test.package"/> * </bean>

* + *

Note: This class requires Hibernate 3.2 or later, with the + * Java Persistence API and the Hibernate Annotations add-on present. + * * @author Juergen Hoeller * @since 1.2.2 * @see #setDataSource @@ -82,7 +82,7 @@ public class AnnotationSessionFactoryBean extends LocalSessionFactoryBean implem private static final String PACKAGE_INFO_SUFFIX = ".package-info"; - private Class[] annotatedClasses; + private Class[] annotatedClasses; private String[] annotatedPackages; @@ -113,19 +113,19 @@ public class AnnotationSessionFactoryBean extends LocalSessionFactoryBean implem /** * Specify annotated classes, for which mappings will be read from - * class-level JDK 1.5+ annotation metadata. + * class-level annotation metadata. * @see org.hibernate.cfg.AnnotationConfiguration#addAnnotatedClass(Class) */ - public void setAnnotatedClasses(Class[] annotatedClasses) { + public void setAnnotatedClasses(Class... annotatedClasses) { this.annotatedClasses = annotatedClasses; } /** * Specify the names of annotated packages, for which package-level - * JDK 1.5+ annotation metadata will be read. + * annotation metadata will be read. * @see org.hibernate.cfg.AnnotationConfiguration#addPackage(String) */ - public void setAnnotatedPackages(String[] annotatedPackages) { + public void setAnnotatedPackages(String... annotatedPackages) { this.annotatedPackages = annotatedPackages; } @@ -136,7 +136,7 @@ public class AnnotationSessionFactoryBean extends LocalSessionFactoryBean implem * classes in the classpath. This is analogous to Spring's component-scan feature * ({@link org.springframework.context.annotation.ClassPathBeanDefinitionScanner}). */ - public void setPackagesToScan(String[] packagesToScan) { + public void setPackagesToScan(String... packagesToScan) { this.packagesToScan = packagesToScan; } @@ -148,7 +148,7 @@ public class AnnotationSessionFactoryBean extends LocalSessionFactoryBean implem * Hibernate's special {@code @org.hibernate.annotations.Entity}. * @see #setPackagesToScan */ - public void setEntityTypeFilters(TypeFilter[] entityTypeFilters) { + public void setEntityTypeFilters(TypeFilter... entityTypeFilters) { this.entityTypeFilters = entityTypeFilters; } diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate3/support/HibernateDaoSupport.java b/spring-orm/src/main/java/org/springframework/orm/hibernate3/support/HibernateDaoSupport.java index e495fc8a9c7..3b7fc1468d2 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate3/support/HibernateDaoSupport.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate3/support/HibernateDaoSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,6 +46,11 @@ import org.springframework.orm.hibernate3.SessionFactoryUtils; * by default. A custom HibernateTemplate instance can be used through overriding * {@link #createHibernateTemplate}. * + *

NOTE: As of Hibernate 3.0.1, transactional Hibernate access code can + * also be coded in plain Hibernate style. Hence, for newly started projects, + * consider adopting the standard Hibernate3 style of coding data access objects + * instead, based on {@link org.hibernate.SessionFactory#getCurrentSession()}. + * * @author Juergen Hoeller * @since 1.2 * @see #setSessionFactory @@ -105,8 +110,8 @@ public abstract class HibernateDaoSupport extends DaoSupport { * You may introspect its configuration, but not modify the configuration * (other than from within an {@link #initDao} implementation). * Consider creating a custom HibernateTemplate instance via - * {@code new HibernateTemplate(getSessionFactory())}, in which - * case you're allowed to customize the settings on the resulting instance. + * {@code new HibernateTemplate(getSessionFactory())}, in which case + * you're allowed to customize the settings on the resulting instance. */ public final HibernateTemplate getHibernateTemplate() { return this.hibernateTemplate; @@ -136,10 +141,10 @@ public abstract class HibernateDaoSupport extends DaoSupport { * @throws DataAccessResourceFailureException if the Session couldn't be created * @throws IllegalStateException if no thread-bound Session found and allowCreate=false * @see org.springframework.orm.hibernate3.SessionFactoryUtils#getSession(SessionFactory, boolean) + * @deprecated as of Spring 3.2.7, in favor of {@link HibernateTemplate} usage */ - protected final Session getSession() - throws DataAccessResourceFailureException, IllegalStateException { - + @Deprecated + protected final Session getSession() throws DataAccessResourceFailureException, IllegalStateException { return getSession(this.hibernateTemplate.isAllowCreate()); } @@ -161,9 +166,11 @@ public abstract class HibernateDaoSupport extends DaoSupport { * @throws DataAccessResourceFailureException if the Session couldn't be created * @throws IllegalStateException if no thread-bound Session found and allowCreate=false * @see org.springframework.orm.hibernate3.SessionFactoryUtils#getSession(SessionFactory, boolean) + * @deprecated as of Spring 3.2.7, in favor of {@link HibernateTemplate} usage */ + @Deprecated protected final Session getSession(boolean allowCreate) - throws DataAccessResourceFailureException, IllegalStateException { + throws DataAccessResourceFailureException, IllegalStateException { return (!allowCreate ? SessionFactoryUtils.getSession(getSessionFactory(), false) : @@ -185,7 +192,9 @@ public abstract class HibernateDaoSupport extends DaoSupport { * @param ex HibernateException that occurred * @return the corresponding DataAccessException instance * @see org.springframework.orm.hibernate3.SessionFactoryUtils#convertHibernateAccessException + * @deprecated as of Spring 3.2.7, in favor of {@link HibernateTemplate} usage */ + @Deprecated protected final DataAccessException convertHibernateAccessException(HibernateException ex) { return this.hibernateTemplate.convertHibernateAccessException(ex); } @@ -197,7 +206,9 @@ public abstract class HibernateDaoSupport extends DaoSupport { * {@link #getSession} and {@link #convertHibernateAccessException}. * @param session the Session to close * @see org.springframework.orm.hibernate3.SessionFactoryUtils#releaseSession + * @deprecated as of Spring 3.2.7, in favor of {@link HibernateTemplate} usage */ + @Deprecated protected final void releaseSession(Session session) { SessionFactoryUtils.releaseSession(session, getSessionFactory()); }