Org.hibernate.exception.JDBCConnectionException: Cannot open connection

3 respostas
B

Pessoal estou começando a utilizar o Hibernate, então estou construindo uma aplicação simples, vendo vários exemplos.
Estou utilizando hibernate 4 (com anotações) , jboss 5.1.

Segue meu código

hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-configuration PUBLIC
		"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
		"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
		
<hibernate-configuration>
	<session-factory>
		<property name = "hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
		<property name = "hibernate.connection.url">jdbc:mysql://localhost/teste</property>
		<property name=	"hibernate.connection.username">root</property>
        <property name=	"hibernate.connection.password">roxette7</property>
        <property name=	"hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
       <!--  <property name="connection.pool_size">10</property> -->
        
        <!-- mapping classes -->
		<mapping class="br.com.dominio.Cadastro"/>
		
	</session-factory>

</hibernate-configuration>

minha classe persistida

package br.com.dominio;


import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;


@Entity

public class Cadastro {
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;
	
	private String nome;
	private int idade;
	
	
	public void setNome(String nome) {
		
		this.nome = nome;
	}
	
	public void setIdade(int idade) {
		
		this.idade = idade;
	}

	public String setNome() {
		
		return this.nome;
	}
	
	public int getIdade() {
		
		return this.idade;
	}
	
	public void setId(int id) {
		
		this.id = id;
	}
	
	public int getId() {
		
		return this.id;
	}
			
}

a classe onde vou chamar e executar a persistencia

package br.com.action;

import java.io.IOException;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.mysql.jdbc.Connection;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;

import br.com.actionform.CadastroFormBean;
import br.com.dominio.Cadastro;

public class CadastroAction extends Action {
	
	public ActionForward execute(ActionMapping m, ActionForm f, HttpServletRequest req, HttpServletResponse resp) throws Exception {
		
		
		/*Connection conexao = null;
		try {
			conexao = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/teste","root","roxette7");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			//throw new ServletException();
			//e.printStackTrace();
		}finally {
			
			try {
				conexao.close();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				//throw new ServletException();
				//e.printStackTrace();
			}
			
		}
		
		System.out.println("Conectado!");*/
		
		CadastroFormBean formu = (CadastroFormBean) f;
		Cadastro c = new Cadastro();
		
		c.setId(1);
		c.setNome(formu.getNome());
		c.setIdade(formu.getIdade());
		//Cria objeto que receberá as configurações
		Configuration cfg = new AnnotationConfiguration();
		//Informe o arquivo XML que contém a configurações
		cfg.configure("hibernate.cfg.xml");
		//Cria uma fábrica de sessões.
		//Deve existir apenas uma instância na aplicação
		SessionFactory sf = cfg.buildSessionFactory();
		// Abre sessão com o Hibernate
		Session session = sf.openSession();
		//Cria uma transação
		Transaction tx = session.beginTransaction();
		session.save(c);
		tx.commit(); // Finaliza transação
		session.close(); // Fecha sessão
		
		//return new ActionForward("/pages/sucessoCadastro");
		return m.findForward("sucessCadastro");
	}

}

Apenas uma observação: Como estou fazendo apenas um exercicio sei que este pode não ser o melhor jeito de se fazer, pois estou ignorando padrões de projetos, mas o faço propositalmente pois o meu objetivo primeiro é entender como fazer a persistencia com o hibernate.
Em relação ao banco de dados acredito que está ok, pois fiz um teste (vários testes) na classe CadastroAction que inclusive está comentado e conectou normalmente.

3 Respostas

F

Olá BELLLABS!

Faça o seguinte teste. Implemente essas duas classes abaixo e verifique se elas compilam normalmente:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


public class ConnectionFactory {
	
	public Connection getConnection() {
		try {
			System.out.println("Conectando no banco...");
			return DriverManager.getConnection("jdbc:mysql://localhost/seubanco","seuusuario", "suasenha");
		} catch(SQLException e) {
			throw new RuntimeException("Nao foi possivel estabelecer a conexao!");
		}
	}
}
public class TestaConexao {
	
	public static void main(String[] args) {
		
		new ConnectionFactory().getConnection();
		System.out.println("Conectado com sucesso!");
	}
}

Caso a classe TestaConexao imprima “Conectado com sucesso!” o problema não está no banco e sim na configuração do hibernate.
Duas coisas importantíssimas que, embora sejam simples, muitas vezes esquecemos:
1º - Verifique NOVAMENTE se o nome do usuário, a senha e o nome do banco estão CORRETOS
2º - Verifique se o driver JDBC do MySQL está setado no seu classpath

Não deixe de verificar se os jars que o hibernate pede estão corretamente setados no classpath.
Após os testes, poste novamente!!!

B

Vi e revi n vezes as libs.
O que decidi fazer então criei uma aplicação apenas com o hibernate igualzinho o que seria a minha aplicação com o struts e gravou numa boa.
Porém quando faço junto com o struts é que dá o erro.

Ei o erro

21:25:21,698 INFO  [ServerImpl] Starting JBoss (Microcontainer)

21:25:21,698 INFO  [ServerImpl] Release ID: JBoss [The Oracle] <a href="http://5.1.0.GA">5.1.0.GA</a> (build: SVNTag=JBoss_5_1_0_GA date=200905221634)

21:25:21,698 INFO  [ServerImpl] Bootstrap URL: null

21:25:21,698 INFO  [ServerImpl] Home Dir: C:\Program Files\jboss-5.1.0.GA-jdk6\<a href="http://jboss-5.1.0.GA">jboss-5.1.0.GA</a>

21:25:21,698 INFO  [ServerImpl] Home URL: file:/C:/Program%20Files/jboss-5.1.0.GA-jdk6/jboss-5.1.0.GA/

21:25:21,698 INFO  [ServerImpl] Library URL: file:/C:/Program%20Files/jboss-5.1.0.GA-jdk6/jboss-5.1.0.GA/lib/

21:25:21,698 INFO  [ServerImpl] Patch URL: null

21:25:21,698 INFO  [ServerImpl] Common Base URL: file:/C:/Program%20Files/jboss-5.1.0.GA-jdk6/jboss-5.1.0.GA/common/

21:25:21,698 INFO  [ServerImpl] Common Library URL: file:/C:/Program%20Files/jboss-5.1.0.GA-jdk6/jboss-5.1.0.GA/common/lib/

21:25:21,698 INFO  [ServerImpl] Server Name: default

21:25:21,698 INFO  [ServerImpl] Server Base Dir: C:\Program Files\jboss-5.1.0.GA-jdk6\<a href="http://jboss-5.1.0.GA">jboss-5.1.0.GA</a>\server

21:25:21,698 INFO  [ServerImpl] Server Base URL: file:/C:/Program%20Files/jboss-5.1.0.GA-jdk6/jboss-5.1.0.GA/server/

21:25:21,698 INFO  [ServerImpl] Server Config URL: file:/C:/Program%20Files/jboss-5.1.0.GA-jdk6/jboss-5.1.0.GA/server/default/conf/

21:25:21,698 INFO  [ServerImpl] Server Home Dir: C:\Program Files\jboss-5.1.0.GA-jdk6\<a href="http://jboss-5.1.0.GA">jboss-5.1.0.GA</a>\server\default

21:25:21,698 INFO  [ServerImpl] Server Home URL: file:/C:/Program%20Files/jboss-5.1.0.GA-jdk6/jboss-5.1.0.GA/server/default/

21:25:21,698 INFO  [ServerImpl] Server Data Dir: C:\Program Files\jboss-5.1.0.GA-jdk6\<a href="http://jboss-5.1.0.GA">jboss-5.1.0.GA</a>\server\default\data

21:25:21,698 INFO  [ServerImpl] Server Library URL: file:/C:/Program%20Files/jboss-5.1.0.GA-jdk6/jboss-5.1.0.GA/server/default/lib/

21:25:21,698 INFO  [ServerImpl] Server Log Dir: C:\Program Files\jboss-5.1.0.GA-jdk6\<a href="http://jboss-5.1.0.GA">jboss-5.1.0.GA</a>\server\default\log

21:25:21,698 INFO  [ServerImpl] Server Native Dir: C:\Program Files\jboss-5.1.0.GA-jdk6\<a href="http://jboss-5.1.0.GA">jboss-5.1.0.GA</a>\server\default\tmp\native

21:25:21,698 INFO  [ServerImpl] Server Temp Dir: C:\Program Files\jboss-5.1.0.GA-jdk6\<a href="http://jboss-5.1.0.GA">jboss-5.1.0.GA</a>\server\default\tmp

21:25:21,698 INFO  [ServerImpl] Server Temp Deploy Dir: C:\Program Files\jboss-5.1.0.GA-jdk6\<a href="http://jboss-5.1.0.GA">jboss-5.1.0.GA</a>\server\default\tmp\deploy

21:25:22,150 INFO  [ServerImpl] Starting Microcontainer, bootstrapURL=file:/C:/Program%20Files/jboss-5.1.0.GA-jdk6/jboss-5.1.0.GA/server/default/conf/bootstrap.xml

21:25:22,588 INFO  [VFSCacheFactory] Initializing VFSCache [org.jboss.virtual.plugins.cache.CombinedVFSCache]

21:25:22,588 INFO  [VFSCacheFactory] Using VFSCache [CombinedVFSCache[real-cache: null]]

21:25:22,808 INFO  [CopyMechanism] VFS temp dir: C:\Program Files\jboss-5.1.0.GA-jdk6\<a href="http://jboss-5.1.0.GA">jboss-5.1.0.GA</a>\server\default\tmp

21:25:22,816 INFO  [ZipEntryContext] VFS force nested jars copy-mode is enabled.

21:25:23,751 INFO  [ServerInfo] Java version: 1.6.0_26,Sun Microsystems Inc.

21:25:23,751 INFO  [ServerInfo] Java Runtime: Java SE Runtime Environment (build 1.6.0_26-b03)

21:25:23,751 INFO  [ServerInfo] Java VM: Java HotSpot 64-Bit Server VM 20.1-b02,Sun Microsystems Inc.

21:25:23,751 INFO  [ServerInfo] OS-System: Windows 7 6.1,amd64

21:25:23,752 INFO  [ServerInfo] VM arguments: -Dprogram.name=JBossTools: JBoss 5.1 Runtime -Xms256m -Xmx768m -XX:MaxPermSize=256m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djava.endorsed.dirs=C:\Program Files\jboss-5.1.0.GA-jdk6\<a href="http://jboss-5.1.0.GA">jboss-5.1.0.GA</a>\lib\endorsed -Dfile.encoding=Cp1252

21:25:23,791 INFO  [JMXKernel] Legacy JMX core initialized

21:25:25,394 INFO  [ProfileServiceBootstrap] Loading profile: ProfileKey@6e9c2192[domain=default, server=default, name=default]

21:25:26,362 INFO  [WebService] Using RMI server codebase: <a href="http://localhost:8083/">http://localhost:8083/</a>

21:25:30,262 INFO  [NativeServerConfig] JBoss Web Services - Stack Native Core

21:25:30,262 INFO  [NativeServerConfig] <a href="http://3.1.2.GA">3.1.2.GA</a>

21:25:30,774 INFO  [AttributeCallbackItem] Owner callback not implemented.

21:25:31,663 INFO  [LogNotificationListener] Adding notification listener for logging mbean jboss.system:service=Logging,type=Log4jService to server org.jboss.mx.server.MBeanServerImpl@393e6226[ defaultDomain=jboss ]

21:25:39,526 INFO  [Ejb3DependenciesDeployer] Encountered deployment AbstractVFSDeploymentContext@[telefone removido]{vfsfile:/C:/Program%20Files/jboss-5.1.0.GA-jdk6/jboss-5.1.0.GA/server/default/deploy/profileservice-secured.jar/}

21:25:39,526 INFO  [Ejb3DependenciesDeployer] Encountered deployment AbstractVFSDeploymentContext@[telefone removido]{vfsfile:/C:/Program%20Files/jboss-5.1.0.GA-jdk6/jboss-5.1.0.GA/server/default/deploy/profileservice-secured.jar/}

21:25:39,526 INFO  [Ejb3DependenciesDeployer] Encountered deployment AbstractVFSDeploymentContext@[telefone removido]{vfsfile:/C:/Program%20Files/jboss-5.1.0.GA-jdk6/jboss-5.1.0.GA/server/default/deploy/profileservice-secured.jar/}

21:25:39,526 INFO  [Ejb3DependenciesDeployer] Encountered deployment AbstractVFSDeploymentContext@[telefone removido]{vfsfile:/C:/Program%20Files/jboss-5.1.0.GA-jdk6/jboss-5.1.0.GA/server/default/deploy/profileservice-secured.jar/}

21:25:41,571 INFO  [JMXConnectorServerService] JMX Connector server: service:jmx:rmi://localhost/jndi/rmi://localhost:1090/jmxconnector

21:25:41,682 INFO  [MailService] Mail Service bound to java:/Mail

21:25:43,601 WARN  [JBossASSecurityMetadataStore] WARNING! POTENTIAL SECURITY RISK. It has been detected that the MessageSucker component which sucks messages from one node to another has not had its password changed from the installation default. Please see the JBoss Messaging user guide for instructions on how to do this.

21:25:43,616 WARN  [AnnotationCreator] No ClassLoader provided, using TCCL: org.jboss.managed.api.annotation.ManagementComponent

21:25:43,664 WARN  [AnnotationCreator] No ClassLoader provided, using TCCL: org.jboss.managed.api.annotation.ManagementComponent

21:25:43,695 INFO  [TransactionManagerService] JBossTS Transaction Service (JTA version - tag:JBOSSTS_4_6_1_GA) - JBoss Inc.

21:25:43,695 INFO  [TransactionManagerService] Setting up property manager MBean and JMX layer

21:25:43,867 INFO  [TransactionManagerService] Initializing recovery manager

21:25:43,992 INFO  [TransactionManagerService] Recovery manager configured

21:25:43,992 INFO  [TransactionManagerService] Binding TransactionManager JNDI Reference

21:25:44,023 INFO  [TransactionManagerService] Starting transaction recovery manager

21:25:44,273 INFO  [AprLifecycleListener] The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre6\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;native;.

21:25:44,304 INFO  [Http11Protocol] Initializing Coyote HTTP/1.1 on http-localhost%2F127.0.0.1-8080

21:25:44,304 INFO  [AjpProtocol] Initializing Coyote AJP/1.3 on ajp-localhost%2F127.0.0.1-8009

21:25:44,335 INFO  [StandardService] Starting service <a href="http://jboss.web">jboss.web</a>

21:25:44,335 INFO  [StandardEngine] Starting Servlet Engine: JBoss Web/2.1.3.GA

21:25:44,366 INFO  [Catalina] Server startup in 63 ms

21:25:44,382 INFO  [TomcatDeployment] deploy, ctxPath=/web-console

21:25:44,865 INFO  [TomcatDeployment] deploy, ctxPath=/invoker

21:25:44,913 INFO  [TomcatDeployment] deploy, ctxPath=/jbossws

21:25:44,976 INFO  [RARDeployment] Required license terms exist, view vfszip:/C:/Program Files/jboss-5.1.0.GA-jdk6/jboss-5.1.0.GA/server/default/deploy/jboss-local-jdbc.rar/META-INF/ra.xml

21:25:44,991 INFO  [RARDeployment] Required license terms exist, view vfszip:/C:/Program Files/jboss-5.1.0.GA-jdk6/jboss-5.1.0.GA/server/default/deploy/jboss-xa-jdbc.rar/META-INF/ra.xml

21:25:45,007 INFO  [RARDeployment] Required license terms exist, view vfszip:/C:/Program Files/jboss-5.1.0.GA-jdk6/jboss-5.1.0.GA/server/default/deploy/jms-ra.rar/META-INF/ra.xml

21:25:45,022 INFO  [RARDeployment] Required license terms exist, view vfszip:/C:/Program Files/jboss-5.1.0.GA-jdk6/jboss-5.1.0.GA/server/default/deploy/mail-ra.rar/META-INF/ra.xml

21:25:45,038 INFO  [RARDeployment] Required license terms exist, view vfszip:/C:/Program Files/jboss-5.1.0.GA-jdk6/jboss-5.1.0.GA/server/default/deploy/quartz-ra.rar/META-INF/ra.xml

21:25:45,085 INFO  [SimpleThreadPool] Job execution threads will use class loader of thread: main

21:25:45,116 INFO  [QuartzScheduler] Quartz Scheduler v.1.5.2 created.

21:25:45,116 INFO  [RAMJobStore] RAMJobStore initialized.

21:25:45,116 INFO  [StdSchedulerFactory] Quartz scheduler DefaultQuartzScheduler initialized from default resource file in Quartz package: 'quartz.properties

21:25:45,116 INFO  [StdSchedulerFactory] Quartz scheduler version: 1.5.2

21:25:45,116 INFO  [QuartzScheduler] Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED started.

21:25:45,412 INFO  [ConnectionFactoryBindingService] Bound ConnectionManager jboss.jca:service=DataSourceBinding,name=DefaultDS to JNDI name 'java:DefaultDS

21:25:45,678 INFO  [ServerPeer] JBoss Messaging <a href="http://1.4.3.GA">1.4.3.GA</a> server [0] started

21:25:45,771 INFO  [ConnectionFactory] Connector bisocket://localhost:4457 has leasing enabled, lease period 10000 milliseconds

21:25:45,771 INFO  [ConnectionFactory] org.jboss.jms.server.connectionfactory.ConnectionFactory@38bf66e5 started

21:25:45,771 INFO  [ConnectionFactoryJNDIMapper] supportsFailover attribute is true on connection factory: jboss.messaging.connectionfactory:service=ClusteredConnectionFactory but post office is non clustered. So connection factory will <em>not</em> support failover

21:25:45,771 INFO  [ConnectionFactoryJNDIMapper] supportsLoadBalancing attribute is true on connection factory: jboss.messaging.connectionfactory:service=ClusteredConnectionFactory but post office is non clustered. So connection factory will <em>not</em> support load balancing

21:25:45,771 INFO  [ConnectionFactory] Connector bisocket://localhost:4457 has leasing enabled, lease period 10000 milliseconds

21:25:45,771 INFO  [ConnectionFactory] org.jboss.jms.server.connectionfactory.ConnectionFactory@c68bfe0 started

21:25:45,771 INFO  [QueueService] Queue[/queue/ExpiryQueue] started, fullSize=200000, pageSize=2000, downCacheSize=2000

21:25:45,787 INFO  [ConnectionFactory] Connector bisocket://localhost:4457 has leasing enabled, lease period 10000 milliseconds

21:25:45,787 INFO  [ConnectionFactory] org.jboss.jms.server.connectionfactory.ConnectionFactory@669efb83 started

21:25:45,787 INFO  [QueueService] Queue[/queue/DLQ] started, fullSize=200000, pageSize=2000, downCacheSize=2000

21:25:45,849 INFO  [ConnectionFactoryBindingService] Bound ConnectionManager jboss.jca:service=ConnectionFactoryBinding,name=JmsXA to JNDI name 'java:JmsXA

21:25:46,114 INFO  [JBossASKernel] Created KernelDeployment for: profileservice-secured.jar

21:25:46,114 INFO  [JBossASKernel] installing bean: jboss.j2ee:jar=profileservice-secured.jar,name=SecureProfileService,service=EJB3

21:25:46,114 INFO  [JBossASKernel]   with dependencies:

21:25:46,114 INFO  [JBossASKernel]   and demands:

21:25:46,114 INFO  [JBossASKernel] 	jndi:SecureManagementView/remote-org.jboss.deployers.spi.management.ManagementView

21:25:46,114 INFO  [JBossASKernel] 	jboss.ejb:service=EJBTimerService

21:25:46,114 INFO  [JBossASKernel]   and supplies:

21:25:46,114 INFO  [JBossASKernel] 	Class:org.jboss.profileservice.spi.ProfileService

21:25:46,130 INFO  [JBossASKernel] 	jndi:SecureProfileService/remote

21:25:46,130 INFO  [JBossASKernel] 	jndi:SecureProfileService/remote-org.jboss.profileservice.spi.ProfileService

21:25:46,130 INFO  [JBossASKernel] Added bean(jboss.j2ee:jar=profileservice-secured.jar,name=SecureProfileService,service=EJB3) to KernelDeployment of: profileservice-secured.jar

21:25:46,130 INFO  [JBossASKernel] installing bean: jboss.j2ee:jar=profileservice-secured.jar,name=SecureDeploymentManager,service=EJB3

21:25:46,130 INFO  [JBossASKernel]   with dependencies:

21:25:46,130 INFO  [JBossASKernel]   and demands:

21:25:46,130 INFO  [JBossASKernel] 	jboss.ejb:service=EJBTimerService

21:25:46,130 INFO  [JBossASKernel]   and supplies:

21:25:46,130 INFO  [JBossASKernel] 	jndi:SecureDeploymentManager/remote-org.jboss.deployers.spi.management.deploy.DeploymentManager

21:25:46,130 INFO  [JBossASKernel] 	Class:org.jboss.deployers.spi.management.deploy.DeploymentManager

21:25:46,130 INFO  [JBossASKernel] 	jndi:SecureDeploymentManager/remote

21:25:46,130 INFO  [JBossASKernel] Added bean(jboss.j2ee:jar=profileservice-secured.jar,name=SecureDeploymentManager,service=EJB3) to KernelDeployment of: profileservice-secured.jar

21:25:46,130 INFO  [JBossASKernel] installing bean: jboss.j2ee:jar=profileservice-secured.jar,name=SecureManagementView,service=EJB3

21:25:46,130 INFO  [JBossASKernel]   with dependencies:

21:25:46,130 INFO  [JBossASKernel]   and demands:

21:25:46,130 INFO  [JBossASKernel] 	jboss.ejb:service=EJBTimerService

21:25:46,130 INFO  [JBossASKernel]   and supplies:

21:25:46,130 INFO  [JBossASKernel] 	jndi:SecureManagementView/remote-org.jboss.deployers.spi.management.ManagementView

21:25:46,130 INFO  [JBossASKernel] 	Class:org.jboss.deployers.spi.management.ManagementView

21:25:46,130 INFO  [JBossASKernel] 	jndi:SecureManagementView/remote

21:25:46,130 INFO  [JBossASKernel] Added bean(jboss.j2ee:jar=profileservice-secured.jar,name=SecureManagementView,service=EJB3) to KernelDeployment of: profileservice-secured.jar

21:25:46,130 INFO  [EJB3EndpointDeployer] Deploy AbstractBeanMetaData@2b6f5657{name=jboss.j2ee:jar=profileservice-secured.jar,name=SecureProfileService,service=EJB3_endpoint bean=org.jboss.ejb3.endpoint.deployers.impl.EndpointImpl properties=[container] constructor=null autowireCandidate=true}

21:25:46,130 INFO  [EJB3EndpointDeployer] Deploy AbstractBeanMetaData@3fd09ad6{name=jboss.j2ee:jar=profileservice-secured.jar,name=SecureDeploymentManager,service=EJB3_endpoint bean=org.jboss.ejb3.endpoint.deployers.impl.EndpointImpl properties=[container] constructor=null autowireCandidate=true}

21:25:46,130 INFO  [EJB3EndpointDeployer] Deploy AbstractBeanMetaData@2dbf20f6{name=jboss.j2ee:jar=profileservice-secured.jar,name=SecureManagementView,service=EJB3_endpoint bean=org.jboss.ejb3.endpoint.deployers.impl.EndpointImpl properties=[container] constructor=null autowireCandidate=true}

21:25:46,349 INFO  [SessionSpecContainer] Starting jboss.j2ee:jar=profileservice-secured.jar,name=SecureDeploymentManager,service=EJB3

21:25:46,365 INFO  [EJBContainer] STARTED EJB: org.jboss.profileservice.ejb.SecureDeploymentManager ejbName: SecureDeploymentManager

21:25:46,427 INFO  [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:
SecureDeploymentManager/remote - EJB3.x Default Remote Business Interface
SecureDeploymentManager/remote-org.jboss.deployers.spi.management.deploy.DeploymentManager - EJB3.x Remote Business Interface

21:25:46,474 INFO [SessionSpecContainer] Starting jboss.j2ee:jar=profileservice-secured.jar,name=SecureManagementView,service=EJB3
21:25:46,474 INFO [EJBContainer] STARTED EJB: org.jboss.profileservice.ejb.SecureManagementView ejbName: SecureManagementView
21:25:46,490 INFO [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:

SecureManagementView/remote - EJB3.x Default Remote Business Interface
SecureManagementView/remote-org.jboss.deployers.spi.management.ManagementView - EJB3.x Remote Business Interface

21:25:46,521 INFO [SessionSpecContainer] Starting jboss.j2ee:jar=profileservice-secured.jar,name=SecureProfileService,service=EJB3
21:25:46,537 INFO [EJBContainer] STARTED EJB: org.jboss.profileservice.ejb.SecureProfileServiceBean ejbName: SecureProfileService
21:25:46,537 INFO [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:

SecureProfileService/remote - EJB3.x Default Remote Business Interface
SecureProfileService/remote-org.jboss.profileservice.spi.ProfileService - EJB3.x Remote Business Interface
21:25:46,646 INFO  [TomcatDeployment] deploy, ctxPath=/admin-console

21:25:46,724 INFO  [config] Initializing Mojarra (1.2_12-b01-FCS) for context '/admin-console

21:25:48,143 INFO  [TomcatDeployment] deploy, ctxPath=/Me

21:25:48,285 INFO  [XmlConfigurationProvider] Parsing configuration file [struts-default.xml]

21:25:48,410 INFO  [XmlConfigurationProvider] Parsing configuration file [struts-plugin.xml]

21:25:48,456 INFO  [XmlConfigurationProvider] Unable to locate configuration files of the name struts.xml, skipping

21:25:48,456 INFO  [XmlConfigurationProvider] Parsing configuration file [struts.xml]

21:25:51,015 INFO  [TomcatDeployment] deploy, ctxPath=/ST1

21:25:51,078 INFO  [TomcatDeployment] deploy, ctxPath=/bebida

21:25:51,125 INFO  [TomcatDeployment] deploy, ctxPath=/jmx-console

21:25:51,250 INFO  [TomcatDeployment] deploy, ctxPath=/outrabebida

21:25:52,342 INFO  [TomcatDeployment] deploy, ctxPath=/teste

21:25:52,390 INFO  [TomcatDeployment] deploy, ctxPath=/virginia

21:25:52,452 INFO  [Http11Protocol] Starting Coyote HTTP/1.1 on http-localhost%2F127.0.0.1-8080

21:25:52,468 INFO  [AjpProtocol] Starting Coyote AJP/1.3 on ajp-localhost%2F127.0.0.1-8009

21:25:52,483 INFO  [ServerImpl] JBoss (Microcontainer) [<a href="http://5.1.0.GA">5.1.0.GA</a> (build: SVNTag=JBoss_5_1_0_GA date=200905221634)] Started in 30s:785ms

21:25:58,676 INFO  [TomcatDeployment] deploy, ctxPath=/hib

21:26:24,723 INFO  [Version] HCANN000001: Hibernate Commons Annotations {4.0.0.CR2}

21:26:24,723 INFO  [Version] HHH000412: Hibernate Core {4.0.0.CR4}

21:26:24,739 INFO  [Environment] HHH000206: hibernate.properties not found

21:26:24,739 INFO  [Environment] HHH000021: Bytecode provider name : javassist

21:26:24,755 INFO  [Configuration] HHH000043: Configuring from resource: hibernate.cfg.xml

21:26:24,755 INFO  [Configuration] HHH000040: Configuration resource: hibernate.cfg.xml

21:26:24,787 WARN  [DTDEntityResolver] HHH000223: Recognized obsolete hibernate namespace <a href="http://hibernate.sourceforge.net/">http://hibernate.sourceforge.net/</a>. Use namespace <a href="http://www.hibernate.org/dtd/">http://www.hibernate.org/dtd/</a> instead. Refer to Hibernate 3.6 Migration Guide!

21:26:24,818 INFO  [Configuration] HHH000041: Configured SessionFactory: null

21:26:25,021 INFO  [DriverManagerConnectionProviderImpl] HHH000402: Using Hibernate built-in connection pool (not for production use!)

21:26:25,036 INFO  [DriverManagerConnectionProviderImpl] HHH000115: Hibernate connection pool size: 20

21:26:25,036 INFO  [DriverManagerConnectionProviderImpl] HHH000006: Autocommit mode: false

21:26:25,036 INFO  [DriverManagerConnectionProviderImpl] HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost/teste]

21:26:25,036 INFO  [DriverManagerConnectionProviderImpl] HHH000046: Connection properties: {user=root, password=****}

21:26:25,270 INFO  [Dialect] HHH000400: Using dialect: org.hibernate.dialect.MySQLInnoDBDialect

21:26:25,301 INFO  [TransactionFactoryInitiator] HHH000399: Using default transaction strategy (direct JDBC transactions)

21:26:25,301 INFO  [ASTQueryTranslatorFactory] HHH000397: Using ASTQueryTranslatorFactory

21:26:25,520 ERROR [[action]] Servlet.service() for servlet action threw exception

java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;

at br.com.action.Teste.t(Teste.java:24)

at br.com.action.CadastroAction.execute(CadastroAction.java:18)

at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)

at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)

at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)

at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)

at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)

at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)

at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)

at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)

at java.lang.Thread.run(Unknown Source)

O código que eu fiz na aplicação de teste é igual a aplicação com struts, exceto pelo fato de ser uma aplicação sem o struts. Inclusive na aplicação de teste incluir todas as libs (até as do struts) que uso na aplicação que dá o erro para ter a certeza que não foram libs. Não entendo porque dentro da minha action não executa o código relacionado ao hibernate

F

Olá BELLLABS!!!

Você está usando o Struts 2? Caso esteja, faça a seguinte alteração:

Troque o nome do pacote de “br.com.actionform” para “br.com.action”. No Struts 2 existe três maneiras de configurar suas Actions: via xml, via convenções e via anotações. Se você estiver usando a segunda opção (via convenções) é obrigatório que o nome do pacote onde estejam suas actions terminem com action, actions ou struts2.

Abraços!!!

Criado 16 de outubro de 2011
Ultima resposta 18 de out. de 2011
Respostas 3
Participantes 2