Bom dia a todos.
Estou com um problema que acredito que possam me ajudar.
Não sou muito expert no assunto, mas já tentei várias formas.
O que acontece é o seguinte, estou desenvolvendo uma webapp com security + primefaces, até o momento nada mais faz que gerenciar um crud de usuários.
Quando eu faço um crud diretamente da app, fica tudo legal, porém se eu altero dados manualmente no banco, quando eu acho a pagina que faz uma busca não me retorna os dados atualizados, só me retorna, quando eu starto o servidor novamente.
Isso eu estava usando sessionFactory.openSession, quando eu mudei para sessionFactory.getCurrentSession, recebo o seguinte erro.
No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here] with root cause
segue código
web.xml
<display-name>spring + security + hibernate</display-name>
<error-page>
<error-code>403</error-code>
<location>/pages/error/forbidden.jsf</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/pages/error/notFound.jsf</location>
</error-page>
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/pages/home.jsf</location>
</error-page>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-config.xml
/WEB-INF/spring-security.xml
</param-value>
</context-param>
<context-param>
<param-name>primefaces.SKIN</param-name>
<param-value>trontastic</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Resource Servlet</servlet-name>
<servlet-class>org.primefaces.resource.ResourceServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Resource Servlet</servlet-name>
<url-pattern>/primefaces_resource/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
spring-config.xml
<!-- habilita a configuração por annotations -->
<context:annotation-config />
<!-- define os pacotes/subpacotes que onde serão procurados beans do spring -->
<context:component-scan base-package="com.web" />
<!-- Propriedades do hibernate -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect
</prop>
<prop key="hibernate.connection.url">jdbc:mysql://localhost:3306/webapp
</prop>
<prop key="hibernate.connection.driver_class">com.mysql.jdbc.Driver
</prop>
<prop key="hibernate.connection.username">root
</prop>
<prop key="hibernate.connection.password">root
</prop>
<prop key="hibernate.connection.autocommit">false
</prop>
<!--Ehcache Configs -->
<prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
<!--configuration pool -->
<prop key="connection.pool_size">2</prop>
<prop key="current_session_context_class">thread</prop>
<!--this will show us all sql statements -->
<prop key="hibernate.show_sql">false</prop>
<!-- Generate DataBase tables -->
<!-- <prop key="hibernate.hbm2ddl.auto">create</prop> -->
<!--<prop key="hibernate.max_fetch_depth">2</prop> -->
</props>
</property>
<property name="annotatedClasses">
<list>
<value>com.web.authorizationgroup.entity.UserEntity</value>
<value>com.web.authorizationgroup.entity.ProfileEntity</value>
</list>
</property>
</bean>
</beans>
public class ConfigDAO {
Session session;
SessionFactory sessionFactory;
public void doSession(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
session = sessionFactory.getCurrentSession();
}
public void adiciona(Object object) {
session.beginTransaction();
session.saveOrUpdate(object);
session.getTransaction().commit();
session.close();
}
public void update(Object object) {
session.beginTransaction();
session.saveOrUpdate(object);
session.getTransaction().commit();
session.close();
}
public void delete(Object object) {
session.beginTransaction();
session.delete(object);
session.getTransaction().commit();
session.close();
}
public Object idSearch(Class<?> classe, String id) {
int idObj = Integer.valueOf(id);
Object obj = (Object) session.get(classe, idObj);
session.close();
return obj;
}
public List<Object> filterSearch(Class<?> classe,
List<Criterion> listCriterias) {
DetachedCriteria dcrit = DetachedCriteria.forClass(classe);
for (Criterion criterion : listCriterias) {
dcrit.add(criterion);
}
Criteria criteria = dcrit.getExecutableCriteria(session);
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
List<Object> result = criteria.list();
session.close();
return result;
}
}
Estou usando autowired no meu controller, sabem me dizer o que está acontecendo?
@Autowired
private SessionFactory sessionFactory;
Obrigado.