Raible's Wiki

Raible Designs
Wiki Home
News
Recent Changes

AppFuse

Homepage
  - Korean
  - Chinese
  - Italian
  - Japanese

QuickStart Guide
  - Chinese
  - French
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish
  - Japanese

User Guide
  - Korean
  - Chinese

Tutorials
  - Chinese
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish

FAQ
  - Korean

Latest Downloads

Other Applications

Struts Resume
Security Example
Struts Menu

Set your name in
UserPreferences


Referenced by
Main
TextFormattingRules
WhatIsWiki




JSPWiki v2.2.33

[RSS]


Hide Menu

SandBox


This is version 299. It is not the current version, and thus it cannot be edited.
[Back to current version]   [Restore this version]


this mailing list thread.

What is this SandBox?


     SqlRowSet rset = getJdbcTemplate().queryForRowSet(
             "select id, name from mytest where id > ? and name < ?",
             new Object[] {new Long(1)"Z"});
     int i = 0;
     while (rset.next()) {
         i++;
         System.out.println("Row" + i + " " + rset.getString(2));
     }

The DAO layer has the Hibernate sessionFactory injected (made available) to it through Spring and this entry in applicationContext-hibernate.xml:
<property name="sessionFactory"><ref local="sessionFactory"/></property> 

So to access the Hibernate session from within your DAO, place a method like this in your DAO:


    	Session session = SessionFactoryUtils.getSession(getSessionFactory(), false);

  • 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:
    private void createApplicationContext() {
        if (ctx == null) {
            ctx =    
          WebApplicationContextUtils.getRequiredWebApplicationContext(servlet.getServletContext());
        }
    }

    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;
    }


Attachments:


Go to top   More info...   Attach file...
This particular version was published on 06-Nov-2006 13:52:36 MST by BenGill.