1
The project is divided into the following modules:
- test-persistence;
- test-services;
- web test;
I use Glassfish 4 as an application server and it has a connection pool configured for connections to the database created in Mysql.
Class of service used:
User service
@Transactional
@Service
public class UsuarioService implements IUsuarioService {
private UsuarioDAO usuarioDAO;
@Autowired
public UsuarioService(UsuarioDAO usuarioDAO) {
this.usuarioDAO = usuarioDAO;
}
@Override
@Transactional
public void salvar(Usuario pUsuario) {
pUsuario.setStatus(Status.DISPONIVEL);
this.usuarioDAO.salvar(pUsuario);
}
@Override
public void atualizar(Usuario pUsuario) {
this.usuarioDAO.atualizar(pUsuario);
}
@Override
public void excluir(Usuario pUsuario) {
this.usuarioDAO.excluir(pUsuario);
}
@Override
@Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED)
public Usuario carregar(Integer pUsuario) {
return this.usuarioDAO.carregar(pUsuario);
}
@Override
@Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED)
public Usuario carregarPorLogin(String pLogin) {
return this.usuarioDAO.carregarPorLogin(pLogin);
}
@Override
@Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED)
public Usuario carregarPorRg(String pRg) {
return this.usuarioDAO.carregarPorRg(pRg);
}
@Override
@Transactional(readOnly = true, isolation = Isolation.SERIALIZABLE)
public List<Usuario> listar() {
return this.usuarioDAO.listar();
}
}
Configuration files for Spring:
spring-config-persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans ...>
<context:component-scan base-package="org.teste.dao.impl" />
<tx:jta-transaction-manager />
<tx:annotation-driven mode="aspectj" />
<!-- Configuração do Hibernate -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jtaTransactionManager" ref="transactionManager" />
<property name="packagesToScan" value="org.teste.model" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">
true
</prop>
<prop key="hibernate.generate_statistics">
true
</prop>
<prop key="hibernate.generator_mappings">
true
</prop>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQL5InnoDBDialect
</prop>
</props>
</property>
</bean>
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/TESTE_Pool" />
<bean
class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
</beans
spring-config-services.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans ...>
<import resource="classpath*:/spring-config-persistence.xml" />
<context:component-scan base-package="org.teste.rn" />
</beans>
spring-config-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans ...>
<import resource="classpath*:/spring-config-services.xml" />
<mvc:annotation-driven />
<context:component-scan base-package="org.teste.web.controllers" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/pages/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
Web configuration file:
web xml.
<?xml version="1.0" encoding="UTF-8"?>
<web-app ...>
<display-name>teste-web</display-name>
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-config-web.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
JSP page used:
cadastro_usuario.jsp
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<title>Cadastro de Usuários</title>
</head>
<body>
<form:form modelAttribute="usuario" action="executar_cadastro"
method="POST">
<label for="nome">Nome:</label>
<form:input path="nome" />
<label for="login">Login:</label>
<form:input path="login" />
<label for="senha">Senha:</label>
<form:input path="senha" />
<label for="rg">RG:</label>
<form:input path="rg" />
<label for="cpf">CPF:</label>
<form:input path="cpf" />
<label for="endereco.endereco">Endereço:</label>
<form:input path="endereco.endereco" />
<label for="endereco.numero">Número:</label>
<form:input path="endereco.numero" />
<label for="endereco.complemento">Complemento:</label>
<form:input path="endereco.complemento" />
<label for="endereco.cep">CEP:</label>
<form:input path="endereco.cep" />
<label for="endereco.bairro">Bairro:</label>
<form:input path="endereco.bairro" />
<label for="endereco.cidade">Cidade:</label>
<form:input path="endereco.cidade" />
<label for="endereco.estado">Estado:</label>
<form:input path="endereco.estado" />
<label for="contato.telefone">Número do Telefone:</label>
<form:input path="contato.telefone" />
<label for="contato.celular">Número do Celular:</label>
<form:input path="contato.celular" />
<label for="observacoes">Observações:</label>
<form:input path="observacoes" />
<input type="submit" value="Cadastrar"></input>
</form:form>
</body>
</html>
Controller class used:
User controller
@Controller
public class UsuarioController {
private IUsuarioService usuarioService;
@Autowired
public UsuarioController(IUsuarioService usuarioService) {
this.usuarioService = usuarioService;
}
@RequestMapping(value = "/cadastro_usuario")
public String cadastro(Map<String, Object> model) {
if (model.get("usuario") == null) {
model.put("usuario", new Usuario());
}
return "cadastro_usuario";
}
@RequestMapping(value = "/executar_cadastro", method = RequestMethod.POST)
public String executarCadastro(Usuario usuario) {
usuarioService.salvar(usuario);
return "redirect:/cadastro_usuario";
}
}
Issues
1 - The problem I’m having is when I try to register a user using the page cadastro_usuario.jsp, I fill the fields correctly, but when I click the sign up button I am presented with the following error:
HTTP Status 500 - Internal Server Error
type Exception report
message Internal Server Error
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.orm.hibernate4.HibernateSystemException: Unable to locate current JTA transaction; nested exception is org.hibernate.HibernateException: Unable to locate current JTA transaction
root cause
org.springframework.orm.hibernate4.HibernateSystemException: Unable to locate current JTA transaction; nested exception is org.hibernate.HibernateException: Unable to locate current JTA transaction
root cause
org.hibernate.HibernateException: Unable to locate current JTA transaction
note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.0 logs.
GlassFish Server Open Source Edition 4.0
I do not know where I went wrong or if it is lack of some other configuration so to whom it may interest I thank this already.
UPDATE
Hibernateuteusuariodao
@Repository
public class HibernateUsuarioDAO implements UsuarioDAO {
private SessionFactory sessionFactory;
@Autowired
public HibernateUsuarioDAO(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
@Override
public void salvar(Usuario pUsuario) {
this.sessionFactory.getCurrentSession().save(pUsuario);
}
@Override
public void atualizar(Usuario pUsuario) {
if (pUsuario.getPermissao() == null
|| pUsuario.getPermissao().size() == 0) {
Usuario usuarioPermissao = this.carregar(pUsuario.getCodigo());
pUsuario.setPermissao(usuarioPermissao.getPermissao());
this.sessionFactory.getCurrentSession().evict(usuarioPermissao);
}
this.sessionFactory.getCurrentSession().update(pUsuario);
}
@Override
public void excluir(Usuario pUsuario) {
this.sessionFactory.getCurrentSession().delete(pUsuario);
}
@Override
public Usuario carregar(Integer pCodigo) {
return (Usuario) this.sessionFactory.getCurrentSession().get(
Usuario.class, pCodigo);
}
@Override
public Usuario carregarPorLogin(String pLogin) {
String hql = "select t from Usuario t where t.login = :login";
Query consulta = this.sessionFactory.getCurrentSession().createQuery(
hql);
consulta.setString("login", pLogin);
return (Usuario) consulta.uniqueResult();
}
@Override
public Usuario carregarPorRg(String pRg) {
String hql = "select t from Usuario t where t.rg = :rg";
Query consulta = this.sessionFactory.getCurrentSession().createQuery(
hql);
consulta.setString("rg", pRg);
return (Usuario) consulta.uniqueResult();
}
@Override
public List<Usuario> listar() {
return this.sessionFactory.getCurrentSession()
.createCriteria(Usuario.class).list();
}
}
UPDATE 2
Log of the Glassfish
Server shutdown initiated
Unregistered com.sun.enterprise.glassfish.bootstrap.osgi.EmbeddedOSGiGlassFishImpl@18b0c12 from service registry.
FileMonitoring shutdown
JMXStartupService: Stopped JMXConnectorServer: null
JMXStartupService and JMXConnectors have been shut down.
WebModule[null] ServletContext.log():Destroying Spring FrameworkServlet 'DispatcherServlet'
JdbcRuntimeExtension, getAllSystemRAResourcesAndPools = [GlassFishConfigBean.org.glassfish.jdbc.config.JdbcResource, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcResource, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcConnectionPool, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcConnectionPool, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcConnectionPool, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcResource]
RAR7094: __ds_jdbc_ra shutdown successful.
Running GlassFish Version: GlassFish Server Open Source Edition 4.0 (build 89)
Server log file is using Formatter class: com.sun.enterprise.server.logging.ODLLogFormatter
SEC1115: Realm [admin-realm] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.
SEC1115: Realm [file] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.
SEC1115: Realm [certificate] of classtype [com.sun.enterprise.security.auth.realm.certificate.CertificateRealm] successfully created.
Grizzly Framework 2.3.1 started in: 130ms - bound to [/0.0.0.0:8.080]
Grizzly Framework 2.3.1 started in: 6ms - bound to [/0.0.0.0:8.181]
Grizzly Framework 2.3.1 started in: 5ms - bound to [/0.0.0.0:4.848]
Authorization Service has successfully initialized.
Grizzly Framework 2.3.1 started in: 5ms - bound to [/0.0.0.0:3.700]
this.makeModuleFor(org.glassfish.main.web.glue, null) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.web.glue [263]], State = [READY]
this.makeModuleFor(org.glassfish.web.javax.servlet.jsp, null) returned OSGiModuleImpl:: Bundle = [org.glassfish.web.javax.servlet.jsp [149]], State = [READY]
visiting unvisited references
Grave: Exception while visiting javax.swing.JTable
Grave: SEC5054: Certificate has expired: [
[
Version: V3
...
]
Algorithm: [SHA1withRSA]
Signature:
...
]
SEC1002: Security Manager is OFF.
SEC1010: Entering Security Startup Service
SEC1143: Loading policy provider com.sun.enterprise.security.provider.PolicyWrapper.
SEC1011: Security Service(s) Started Successfully
Created HTTP listener http-listener-1 on host/port 0.0.0.0:8080
Created HTTP listener http-listener-2 on host/port 0.0.0.0:8181
Created HTTP listener admin-listener on host/port 0.0.0.0:4848
Created virtual server server
Created virtual server __asadmin
Setting JAAS app name glassfish-web
Virtual server server loaded default web module
visiting unvisited references
WebModule[null] ServletContext.log():No Spring WebApplicationInitializer types detected on classpath
Grave: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
Grave: SLF4J: Defaulting to no-operation (NOP) logger implementation
Grave: SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
WebModule[null] ServletContext.log():Initializing Spring FrameworkServlet 'DispatcherServlet'
visiting unvisited references
HV000001: Hibernate Validator 5.0.0.Final
Grave: log4j:WARN No appenders could be found for logger (org.jboss.logging).
Grave: log4j:WARN Please initialize the log4j system properly.
Grave: log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Loading application [sgct-web] at [/sgct]
Loading application sgct-web done in 25.502 ms
Registered org.glassfish.ha.store.adapter.cache.ShoalBackingStoreProxy for persistence-type = replicated in BackingStoreFactoryRegistry
GlassFish Server Open Source Edition 4.0 (89) startup time : Felix (4.027ms), startup services(27.485ms), total(31.512ms)
Initiating Jersey application, version Jersey: 2.0 2013-05-03 14:50:15...
Initiating Jersey application, version Jersey: 2.0 2013-05-03 14:50:15...
Listening to REST requests at context: /management/domain.
visiting unvisited references
Registered com.sun.enterprise.glassfish.bootstrap.osgi.EmbeddedOSGiGlassFishImpl@10e7b89 as OSGi service registration: org.apache.felix.framework.ServiceRegistrationImpl@78459f.
this.makeModuleFor(org.glassfish.main.admingui.console-common, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-common [48]], State = [READY]
this.makeModuleFor(org.glassfish.hk2.hk2, 2.1.92) returned OSGiModuleImpl:: Bundle = [org.glassfish.hk2.hk2 [118]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-plugin-service, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-plugin-service [58]], State = [READY]
this.makeModuleFor(org.glassfish.main.deployment.deployment-client, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.deployment.deployment-client [67]], State = [READY]
this.makeModuleFor(org.glassfish.main.registration.registration-api, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.registration.registration-api [230]], State = [READY]
this.makeModuleFor(org.glassfish.main.registration.registration-impl, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.registration.registration-impl [231]], State = [READY]
this.makeModuleFor(javax.servlet-api, 3.1.0) returned OSGiModuleImpl:: Bundle = [javax.servlet-api [147]], State = [READY]
this.makeModuleFor(javax.servlet.jsp-api, 2.3.1) returned OSGiModuleImpl:: Bundle = [javax.servlet.jsp-api [148]], State = [READY]
this.makeModuleFor(com.sun.el.javax.el, 3.0.0) returned OSGiModuleImpl:: Bundle = [com.sun.el.javax.el [132]], State = [READY]
this.makeModuleFor(com.sun.jsftemplating, 2.1.0) returned OSGiModuleImpl:: Bundle = [com.sun.jsftemplating [186]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.dataprovider, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.dataprovider [63]], State = [READY]
this.makeModuleFor(com.sun.pkg.client, 1.0.0) returned OSGiModuleImpl:: Bundle = [com.sun.pkg.client [229]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-cluster-plugin, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-cluster-plugin [46]], State = [READY]
JMXStartupService has started JMXConnector on JMXService URL service:jmx:rmi://brito-01.mshome.net:8686/jndi/rmi://brito-01.mshome.net:8686/jmxrmi
this.makeModuleFor(org.glassfish.main.admingui.console-jts-plugin, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-jts-plugin [57]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-corba-plugin, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-corba-plugin [51]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-concurrent-plugin, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-concurrent-plugin [50]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-jca-plugin, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-jca-plugin [54]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-jdbc-plugin, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-jdbc-plugin [55]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-jms-plugin, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-jms-plugin [56]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-web-plugin, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-web-plugin [60]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-common, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-common [48]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-updatecenter-plugin, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-updatecenter-plugin [59]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-community-branding-plugin, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-community-branding-plugin [49]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-ejb-lite-plugin, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-ejb-lite-plugin [52]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-ejb-plugin, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-ejb-plugin [53]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-common-full-plugin, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-common-full-plugin [47]], State = [READY]
visiting unvisited references
this.makeModuleFor(org.glassfish.main.admingui.console-common, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-common [48]], State = [READY]
this.makeModuleFor(org.glassfish.hk2.hk2, 2.1.92) returned OSGiModuleImpl:: Bundle = [org.glassfish.hk2.hk2 [118]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-plugin-service, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-plugin-service [58]], State = [READY]
this.makeModuleFor(org.glassfish.main.deployment.deployment-client, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.deployment.deployment-client [67]], State = [READY]
this.makeModuleFor(org.glassfish.main.registration.registration-api, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.registration.registration-api [230]], State = [READY]
this.makeModuleFor(org.glassfish.main.registration.registration-impl, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.registration.registration-impl [231]], State = [READY]
this.makeModuleFor(javax.servlet-api, 3.1.0) returned OSGiModuleImpl:: Bundle = [javax.servlet-api [147]], State = [READY]
this.makeModuleFor(javax.servlet.jsp-api, 2.3.1) returned OSGiModuleImpl:: Bundle = [javax.servlet.jsp-api [148]], State = [READY]
this.makeModuleFor(com.sun.el.javax.el, 3.0.0) returned OSGiModuleImpl:: Bundle = [com.sun.el.javax.el [132]], State = [READY]
this.makeModuleFor(com.sun.jsftemplating, 2.1.0) returned OSGiModuleImpl:: Bundle = [com.sun.jsftemplating [186]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.dataprovider, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.dataprovider [63]], State = [READY]
this.makeModuleFor(com.sun.pkg.client, 1.0.0) returned OSGiModuleImpl:: Bundle = [com.sun.pkg.client [229]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-cluster-plugin, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-cluster-plugin [46]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-jts-plugin, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-jts-plugin [57]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-corba-plugin, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-corba-plugin [51]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-concurrent-plugin, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-concurrent-plugin [50]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-jca-plugin, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-jca-plugin [54]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-jdbc-plugin, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-jdbc-plugin [55]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-jms-plugin, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-jms-plugin [56]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-web-plugin, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-web-plugin [60]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-common, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-common [48]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-updatecenter-plugin, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-updatecenter-plugin [59]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-community-branding-plugin, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-community-branding-plugin [49]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-ejb-lite-plugin, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-ejb-lite-plugin [52]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-ejb-plugin, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-ejb-plugin [53]], State = [READY]
this.makeModuleFor(org.glassfish.main.admingui.console-common-full-plugin, 4.0.0) returned OSGiModuleImpl:: Bundle = [org.glassfish.main.admingui.console-common-full-plugin [47]], State = [READY]
Inicializando Mojarra 2.2.0 ( 20130502-2118 https://svn.java.net/svn/mojarra~svn/tags/2.2.0@11930) para o contexto ''
Loading application [__admingui] at [/]
Informações: Loading application __admingui done in 6.862 ms
Advertência: StandardWrapperValve[DispatcherServlet]: Servlet.service() for servlet DispatcherServlet threw exception
org.hibernate.HibernateException: Unable to locate current JTA transaction
at org.hibernate.context.internal.JTASessionContext.currentSession(JTASessionContext.java:92)
at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:99)
at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1014)
at org.sgct.dao.impl.HibernateUsuarioDAO.salvar(HibernateUsuarioDAO.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy185.salvar(Unknown Source)
at org.sgct.rn.UsuarioService.salvar(UsuarioService.java:28)
at org.sgct.web.controllers.UsuarioController.executarCadastro(UsuarioController.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
Apparently the JTA-related settings are correct. You can post Glassfish logs and your DAO code where you are injecting Session?
– Anthony Accioly
It’s just a kick (based on the possibility of a bug), but try not to repeat the note
@Transactional
method (since the annotation has been defined in the whole class).– utluiz
@utluiz, I took the note
@Transactional
of the methodsalvar()
and the other methods but the error still persists. I also removed the annotation@Transactional
that is in the class signature and I put this annotation in the methods, but still the same error occurs.– klaytonbrito
Right, @klaytonbrito. I noticed that in the log lines
at com.sun.proxy.$Proxy185.salvar(Unknown Source) at org.sgct.rn.UsuarioService.salvar(UsuarioService.java:28)
there is a direct call, as if the Spring AOP was not intercepting the call, which would cause the note@Transactional
did not start a transaction. Do a test: puts the annotation in the methodsalvar
class DAO and see what happens.– utluiz
To inform you, I am using the version 4.0.6 spring. And I’m using GOOD (Bill of Materials) of Spring 4.0.6 to synchronize versions of Spring components.
– klaytonbrito
@utluiz, I have removed all the notes
@Transactional
classUsuarioService
and put this note in the methodsalvar()
classHibernateUsuarioDAO
, but the same error continues to occur.– klaytonbrito
Dude, we’re gonna do some tests. If it works, it’ll come back. 1) Add it with Aspectj:
<tx:annotation-drivem>
2) Arrow the property of Hibernate:hibernate.transaction.manager_lookup_class=org.hibernate.transaction.SunONETransactionManagerLookup
.– Anthony Accioly
@Anthonyaccioly, the exception problem about
JTA transaction
was solved only by removing Aspectj from the tag<tx:annotation-driven />
you quoted, leaving the default mode (mode="proxy"
). What caused this exception to occur I don’t know, maybe a bug. But another exception has emerged:java.sql.SQLException: No database selected
. This problem occurred as you know because of the lack of database definition in the Mysql driver, which in my case is configured in the Glassfish connection pool.– klaytonbrito
Completing my previous answer, I’m talking about this exception because there is an error in the Mysql configuration tutorial with Glassfish (here), as described in the tutorial it is necessary to define a property called
DatabaseName
, however, perhaps by Glassfish, this property is not recognized, so the name of the database must be defined in the propertyURL
to function properly, as described here.– klaytonbrito
Hello klayton, I am happy to help, I will turn the comment in response. About Driver + Glassfish, I find it strange, I have an instance configured with the
databaseName
(ok, it’s on Glassfish 3 and an older version of Driver). That I know of to configure the two ways.– Anthony Accioly
Well, thank you for helping me. About the Mysql driver and Glassfish, I can’t tell you if it’s because of the versions, but in this case the
DatabaseName
did not work and caused the exception ofMySQLException
.– klaytonbrito