Java Doc for AbstractSessionFactoryBean.java in  » J2EE » spring-framework-2.5 » org » springframework » orm » hibernate3 » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » spring framework 2.5 » org.springframework.orm.hibernate3 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.springframework.orm.hibernate3.AbstractSessionFactoryBean

All known Subclasses:   org.springframework.orm.hibernate3.LocalSessionFactoryBean,
AbstractSessionFactoryBean
abstract public class AbstractSessionFactoryBean implements FactoryBean,InitializingBean,DisposableBean,PersistenceExceptionTranslator(Code)
Abstract org.springframework.beans.factory.FactoryBean that creates a Hibernate org.hibernate.SessionFactory within a Spring application context, providing general infrastructure not related to Hibernate's specific configuration API.

This class implements the org.springframework.dao.support.PersistenceExceptionTranslator interface, as autodetected by Spring's org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor , for AOP-based translation of native exceptions to Spring DataAccessExceptions. Hence, the presence of e.g. LocalSessionFactoryBean automatically enables a PersistenceExceptionTranslationPostProcessor to translate Hibernate exceptions.

This class mainly serves as common base class for LocalSessionFactoryBean . For details on typical SessionFactory setup, see the LocalSessionFactoryBean javadoc.
author:
   Juergen Hoeller
since:
   2.0
See Also:   AbstractSessionFactoryBean.setExposeTransactionAwareSessionFactory
See Also:   org.hibernate.SessionFactory.getCurrentSession
See Also:   org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor



Field Summary
final protected  Loglogger
    


Method Summary
public  voidafterPropertiesSet()
     Build and expose the SessionFactory.
protected  voidafterSessionFactoryCreation()
     Hook that allows post-processing after the SessionFactory has been successfully created.
protected  voidbeforeSessionFactoryDestruction()
     Hook that allows shutdown processing before the SessionFactory will be closed.
abstract protected  SessionFactorybuildSessionFactory()
     Build the underlying Hibernate SessionFactory.
protected  DataAccessExceptionconvertHibernateAccessException(HibernateException ex)
     Convert the given HibernateException to an appropriate exception from the org.springframework.dao hierarchy.
public  voiddestroy()
     Close the SessionFactory on bean factory shutdown.
public  DataSourcegetDataSource()
     Return the DataSource to be used by the SessionFactory.
public  ObjectgetObject()
     Return the singleton SessionFactory.
public  ClassgetObjectType()
    
final protected  SessionFactorygetSessionFactory()
     Return the exposed SessionFactory.
protected  booleanisExposeTransactionAwareSessionFactory()
     Return whether to expose a transaction-aware proxy for the SessionFactory.
public  booleanisSingleton()
    
protected  booleanisUseTransactionAwareDataSource()
     Return whether to use a transaction-aware DataSource for the SessionFactory.
public  voidsetDataSource(DataSource dataSource)
     Set the DataSource to be used by the SessionFactory. If set, this will override corresponding settings in Hibernate properties.

If this is set, the Hibernate settings should not define a connection provider to avoid meaningless double configuration.

If using HibernateTransactionManager as transaction strategy, consider proxying your target DataSource with a LazyConnectionDataSourceProxy. This defers fetching of an actual JDBC Connection until the first JDBC Statement gets executed, even within JDBC transactions (as performed by HibernateTransactionManager).

public  voidsetExposeTransactionAwareSessionFactory(boolean exposeTransactionAwareSessionFactory)
     Set whether to expose a transaction-aware current Session from the SessionFactory's getCurrentSession() method, returning the Session that's associated with the current Spring-managed transaction, if any.

Default is "true", letting data access code work with the plain Hibernate SessionFactory and its getCurrentSession() method, while still being able to participate in current Spring-managed transactions: with any transaction management strategy, either local or JTA / EJB CMT, and any transaction synchronization mechanism, either Spring or JTA. Furthermore, getCurrentSession() will also seamlessly work with a request-scoped Session managed by OpenSessionInViewFilter/Interceptor.

Turn this flag off to expose the plain Hibernate SessionFactory with Hibernate's default getCurrentSession() behavior, supporting plain JTA synchronization only.

public  voidsetJdbcExceptionTranslator(SQLExceptionTranslator jdbcExceptionTranslator)
     Set the JDBC exception translator for the SessionFactory, exposed via the PersistenceExceptionTranslator interface.
public  voidsetUseTransactionAwareDataSource(boolean useTransactionAwareDataSource)
     Set whether to use a transaction-aware DataSource for the SessionFactory, i.e.
public  DataAccessExceptiontranslateExceptionIfPossible(RuntimeException ex)
     Implementation of the PersistenceExceptionTranslator interface, as autodetected by Spring's PersistenceExceptionTranslationPostProcessor.
protected  SessionFactorywrapSessionFactoryIfNecessary(SessionFactory rawSf)
     Wrap the given SessionFactory with a proxy, if demanded.

Field Detail
logger
final protected Log logger(Code)
Logger available to subclasses





Method Detail
afterPropertiesSet
public void afterPropertiesSet() throws Exception(Code)
Build and expose the SessionFactory.
See Also:   AbstractSessionFactoryBean.buildSessionFactory()
See Also:   AbstractSessionFactoryBean.wrapSessionFactoryIfNecessary



afterSessionFactoryCreation
protected void afterSessionFactoryCreation() throws Exception(Code)
Hook that allows post-processing after the SessionFactory has been successfully created. The SessionFactory is already available through getSessionFactory() at this point.

This implementation is empty.
throws:
  Exception - in case of initialization failure
See Also:   AbstractSessionFactoryBean.getSessionFactory()




beforeSessionFactoryDestruction
protected void beforeSessionFactoryDestruction()(Code)
Hook that allows shutdown processing before the SessionFactory will be closed. The SessionFactory is still available through getSessionFactory() at this point.

This implementation is empty.
See Also:   AbstractSessionFactoryBean.getSessionFactory()




buildSessionFactory
abstract protected SessionFactory buildSessionFactory() throws Exception(Code)
Build the underlying Hibernate SessionFactory. the raw SessionFactory (potentially to be wrapped with atransaction-aware proxy before it is exposed to the application)
throws:
  Exception - in case of initialization failure



convertHibernateAccessException
protected DataAccessException convertHibernateAccessException(HibernateException ex)(Code)
Convert the given HibernateException to an appropriate exception from the org.springframework.dao hierarchy.

Will automatically apply a specified SQLExceptionTranslator to a Hibernate JDBCException, else rely on Hibernate's default translation.
Parameters:
  ex - HibernateException that occured a corresponding DataAccessException
See Also:   SessionFactoryUtils.convertHibernateAccessException
See Also:   AbstractSessionFactoryBean.setJdbcExceptionTranslator




destroy
public void destroy() throws HibernateException(Code)
Close the SessionFactory on bean factory shutdown.



getDataSource
public DataSource getDataSource()(Code)
Return the DataSource to be used by the SessionFactory.



getObject
public Object getObject()(Code)
Return the singleton SessionFactory.



getObjectType
public Class getObjectType()(Code)



getSessionFactory
final protected SessionFactory getSessionFactory()(Code)
Return the exposed SessionFactory. Will throw an exception if not initialized yet. the SessionFactory (never null)
throws:
  IllegalStateException - if the SessionFactory has not been initialized yet



isExposeTransactionAwareSessionFactory
protected boolean isExposeTransactionAwareSessionFactory()(Code)
Return whether to expose a transaction-aware proxy for the SessionFactory.



isSingleton
public boolean isSingleton()(Code)



isUseTransactionAwareDataSource
protected boolean isUseTransactionAwareDataSource()(Code)
Return whether to use a transaction-aware DataSource for the SessionFactory.



setDataSource
public void setDataSource(DataSource dataSource)(Code)
Set the DataSource to be used by the SessionFactory. If set, this will override corresponding settings in Hibernate properties.

If this is set, the Hibernate settings should not define a connection provider to avoid meaningless double configuration.

If using HibernateTransactionManager as transaction strategy, consider proxying your target DataSource with a LazyConnectionDataSourceProxy. This defers fetching of an actual JDBC Connection until the first JDBC Statement gets executed, even within JDBC transactions (as performed by HibernateTransactionManager). Such lazy fetching is particularly beneficial for read-only operations, in particular if the chances of resolving the result in the second-level cache are high.

As JTA and transactional JNDI DataSources already provide lazy enlistment of JDBC Connections, LazyConnectionDataSourceProxy does not add value with JTA (i.e. Spring's JtaTransactionManager) as transaction strategy.
See Also:   AbstractSessionFactoryBean.setUseTransactionAwareDataSource
See Also:   HibernateTransactionManager
See Also:   org.springframework.transaction.jta.JtaTransactionManager
See Also:   org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy




setExposeTransactionAwareSessionFactory
public void setExposeTransactionAwareSessionFactory(boolean exposeTransactionAwareSessionFactory)(Code)
Set whether to expose a transaction-aware current Session from the SessionFactory's getCurrentSession() method, returning the Session that's associated with the current Spring-managed transaction, if any.

Default is "true", letting data access code work with the plain Hibernate SessionFactory and its getCurrentSession() method, while still being able to participate in current Spring-managed transactions: with any transaction management strategy, either local or JTA / EJB CMT, and any transaction synchronization mechanism, either Spring or JTA. Furthermore, getCurrentSession() will also seamlessly work with a request-scoped Session managed by OpenSessionInViewFilter/Interceptor.

Turn this flag off to expose the plain Hibernate SessionFactory with Hibernate's default getCurrentSession() behavior, supporting plain JTA synchronization only. Alternatively, simply override the corresponding Hibernate property "hibernate.current_session_context_class".
See Also:   SpringSessionContext
See Also:   org.hibernate.SessionFactory.getCurrentSession
See Also:   org.springframework.transaction.jta.JtaTransactionManager
See Also:   HibernateTransactionManager
See Also:   org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
See Also:   org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor




setJdbcExceptionTranslator
public void setJdbcExceptionTranslator(SQLExceptionTranslator jdbcExceptionTranslator)(Code)
Set the JDBC exception translator for the SessionFactory, exposed via the PersistenceExceptionTranslator interface.

Applied to any SQLException root cause of a Hibernate JDBCException, overriding Hibernate's default SQLException translation (which is based on Hibernate's Dialect for a specific target database).
Parameters:
  jdbcExceptionTranslator - the exception translator
See Also:   java.sql.SQLException
See Also:   org.hibernate.JDBCException
See Also:   org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator
See Also:   org.springframework.jdbc.support.SQLStateSQLExceptionTranslator
See Also:   org.springframework.dao.support.PersistenceExceptionTranslator




setUseTransactionAwareDataSource
public void setUseTransactionAwareDataSource(boolean useTransactionAwareDataSource)(Code)
Set whether to use a transaction-aware DataSource for the SessionFactory, i.e. whether to automatically wrap the passed-in DataSource with Spring's TransactionAwareDataSourceProxy.

Default is "false": LocalSessionFactoryBean is usually used with Spring's HibernateTransactionManager or JtaTransactionManager, both of which work nicely on a plain JDBC DataSource. Hibernate Sessions and their JDBC Connections are fully managed by the Hibernate/JTA transaction infrastructure in such a scenario.

If you switch this flag to "true", Spring's Hibernate access will be able to participate in JDBC-based transactions managed outside of Hibernate (for example, by Spring's DataSourceTransactionManager). This can be convenient if you need a different local transaction strategy for another O/R mapping tool, for example, but still want Hibernate access to join into those transactions.

A further benefit of this option is that plain Sessions opened directly via the SessionFactory, outside of Spring's Hibernate support, will still participate in active Spring-managed transactions. However, consider using Hibernate's getCurrentSession() method instead (see javadoc of "exposeTransactionAwareSessionFactory" property).

WARNING: When using a transaction-aware JDBC DataSource in combination with OpenSessionInViewFilter/Interceptor, whether participating in JTA or external JDBC-based transactions, it is strongly recommended to set Hibernate's Connection release mode to "after_transaction" or "after_statement", which guarantees proper Connection handling in such a scenario. In contrast to that, HibernateTransactionManager generally requires release mode "on_close".

Note: If you want to use Hibernate's Connection release mode "after_statement" with a DataSource specified on this LocalSessionFactoryBean (for example, a JTA-aware DataSource fetched from JNDI), switch this setting to "true". Else, the ConnectionProvider used underneath will vote against aggressive release and thus silently switch to release mode "after_transaction".
See Also:   AbstractSessionFactoryBean.setDataSource
See Also:   AbstractSessionFactoryBean.setExposeTransactionAwareSessionFactory
See Also:   org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy
See Also:   org.springframework.jdbc.datasource.DataSourceTransactionManager
See Also:   org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
See Also:   org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor
See Also:   HibernateTransactionManager
See Also:   org.springframework.transaction.jta.JtaTransactionManager




translateExceptionIfPossible
public DataAccessException translateExceptionIfPossible(RuntimeException ex)(Code)
Implementation of the PersistenceExceptionTranslator interface, as autodetected by Spring's PersistenceExceptionTranslationPostProcessor.

Converts the exception if it is a HibernateException; else returns null to indicate an unknown exception.
See Also:   org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor
See Also:   AbstractSessionFactoryBean.convertHibernateAccessException




wrapSessionFactoryIfNecessary
protected SessionFactory wrapSessionFactoryIfNecessary(SessionFactory rawSf)(Code)
Wrap the given SessionFactory with a proxy, if demanded.

The default implementation simply returns the given SessionFactory as-is. Subclasses may override this to implement transaction awareness through a SessionFactory proxy, for example.
Parameters:
  rawSf - the raw SessionFactory as built by AbstractSessionFactoryBean.buildSessionFactory() the SessionFactory reference to expose
See Also:   AbstractSessionFactoryBean.buildSessionFactory()




Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.