Vlw por responder, é algo assim q preciso…
acompanhei as instruções nesse artigo e cheguei no seguinte resultado:
HIbernateUtil
[code]public class HibernateUtil {
private static SessionFactory factory;
static {
Configuration conf = new AnnotationConfiguration();
conf.configure();
factory = conf.buildSessionFactory();
}
public static Session getSession() {
return factory.openSession();
}
public static SessionFactory getSessionFactory() {
return factory;
}[/code]
DaoFactoryImpl:
[code]public class DaoFactoryImpl implements DaoFactory{
private Session session;
public DaoFactoryImpl() {
this.session = HibernateUtil.getSessionFactory().getCurrentSession();
}
…
}[/code]
o filtro:
[code]public class HibernateSessionRequestFilter implements Filter {
private SessionFactory sf;
public void init(FilterConfig filterConfig) throws ServletException {
sf = HibernateUtil.getSessionFactory();
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
try {
sf.getCurrentSession().beginTransaction();
System.out.println("Transaction Started");
// Call the next filter (continue request processing)
chain.doFilter(request, response);
// Commit and cleanup
sf.getCurrentSession().getTransaction().commit();
System.out.println("Transaction Commited");
} catch (StaleObjectStateException staleEx) {
throw staleEx;
} catch (Throwable ex) {
// Rollback only
ex.printStackTrace();
try {
if (sf.getCurrentSession().getTransaction().isActive()) {
sf.getCurrentSession().getTransaction().rollback();
}
} catch (Throwable rbEx) {
rbEx.printStackTrace();
}
// Let others handle it... maybe another interceptor for exceptions?
throw new ServletException(ex);
}
}
public void destroy() {
}
}[/code]
e no web.xml
[code]
HibernateFilter
br.com.cf.vitrola.servlet.filter.HibernateSessionRequestFilter
<filter-mapping>
<filter-name>HibernateFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> [/code]
essa é minha configuração, é isso msm ou esta faltando algo?
porem quando eu inicio a aplicação de cara ja recebo o erro:
[code]javax.servlet.ServletException: org.hibernate.HibernateException: No CurrentSessionContext configured!
br.com.cf.vitrola.servlet.filter.HibernateSessionRequestFilter.doFilter(HibernateSessionRequestFilter.java:57)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
root cause
org.hibernate.HibernateException: No CurrentSessionContext configured!
org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:540)
br.com.cf.vitrola.servlet.filter.HibernateSessionRequestFilter.doFilter(HibernateSessionRequestFilter.java:34)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
[/code]
Alguem ai sabe oq pode estar acontecendo?..
obrigado