AppFuseSupport |
|
| Your trail: |
Difference between
version 76
and
version 75:
| At line 100 changed 1 line. |
| * How do I get hold of the Hibernate session? |
| * How do I get hold of the Hibernate sessionin my DAO? |
| At line 110 changed 3 lines. |
| public Session getHibernateSession() { |
| return SessionFactoryUtils.getSession(getSessionFactory(), false); |
| } |
|
| Session session = SessionFactoryUtils.getSession(getSessionFactory(), false); |
|
| At line 115 changed 2 lines. |
| You could even expose this method through your DAO interface so your 'View' layer can gain access to the session |
| also. |
| * How do I get hold of the Hibernate session in my View code? |
| ;:''To get hold of the Session in the view code, you need to lookup the SessionFactory defined in the applicationContext-hibernate.xml: |
| At line 118 added 7 lines. |
| {{{ |
| private void createApplicationContext() { |
| if (ctx == null) { |
| ctx = |
| WebApplicationContextUtils.getRequiredWebApplicationContext(servlet.getServletContext()); |
| } |
| } |
| At line 126 added 18 lines. |
| public net.sf.hibernate.Session getCurrentHibernateSession() { |
| createApplicationContext(); |
| |
| SessionFactory sessionFactory = (SessionFactory)ctx.getBean("sessionFactory"); |
| SessionHolder sessionHolder = (SessionHolder)TransactionSynchronizationManager.getResource(sessionFactory); |
| net.sf.hibernate.Session currentSession = null; |
| Transaction currentTransaction = null; |
| |
| if (sessionHolder!=null) { |
| currentSession = sessionHolder.getSession(); |
| currentTransaction = sessionHolder.getTransaction(); |
| } |
| return currentSession; |
| } |
|
| }}} |
|
|
Back to AppFuseSupport,
or to the Page History.
|