[RESOLVIDO]Hibernate + tomcat

Estou tendo problemas a usar o hibernate no tomcat.
O problema é que quando eu tento persistir um objeto ele lança a seguinte Exception:

GRAVE: Servlet.service() for servlet [cadastro servlet] in context with path [/com.ecclesia] threw exception
org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:275)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:152)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:286)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:243)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.(InFlightMetadataCollectorImpl.java:175)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:118)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:473)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:84)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:689)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
at com.ecclesia.login.service.UsuarioService.persistir(UsuarioService.java:14)
at com.ecclesia.login.control.LoginControl.cadastro(LoginControl.java:14)
at com.ecclesia.login.servletDatabase.Main.main(Main.java:15)
at com.ecclesia.login.servlet.Cadastro.doGet(Cadastro.java:39)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:853)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1587)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [com.mysql.jdbc.Driver]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:136)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.loadDriverIfPossible(DriverManagerConnectionProviderImpl.java:149)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildCreator(DriverManagerConnectionProviderImpl.java:105)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildPool(DriverManagerConnectionProviderImpl.java:89)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:73)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:107)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:246)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)
… 41 more
Caused by: java.lang.ClassNotFoundException: Could not load requested class : com.mysql.jdbc.Driver
at org.hibernate.boot.registry.classloading.internal.AggregatedClassLoader.findClass(AggregatedClassLoader.java:210)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:133)
… 53 more

Servlet:

@WebServlet (name = “cadastro servlet”, urlPatterns="/cadastro")
public class Cadastro extends HttpServlet {
private static final long serialVersionUID = 1L;
public Cadastro() {

}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String args[] = new String[3];
args[0] = request.getParameter(“nome”);
args[1] = request.getParameter(“email”);
args[2] = request.getParameter(“senha”);
Main.main(args);
PrintWriter i = response.getWriter();
i.println(“FOIII”);

}

Main:

public class Main {
public static void main(String[] args) {
LoginControl userSvc = new LoginControl();
Usuario user = new Usuario(args[0], args[1], args[2]);
userSvc.cadastro(user);

}

LoginControl

public class LoginControl {
public void efetuarLogin(String email,String senha) {

}
public void cadastro(Usuario user) {
UsuarioService userSvc = new UsuarioService();
userSvc.persistir(user);
}

}

UsuarioService:

public class UsuarioService {
public void persistir(Usuario user) {
org.hibernate.cfg.Configuration config = new org.hibernate.cfg.Configuration();
SessionFactory factory = config.configure().buildSessionFactory();
Session session = factory.openSession();
session.flush();
session.beginTransaction();
session.save(user);
session.getTransaction().commit();
session.close();
}
}

Já testei o hibernate fora do servidor e ele funcionou normalmente. Alguem pode me ajudar ?

Por que raios você tem um main num projeto web???

Você criou um projeto web (Dynamic web project)? Ou está usando netbeans? É, ao menos, um projeto web?

Tava pensando em divir o projeto

maven project usando o eclipse

Mas dividir em que sentido, fera?

Posta o pom.xml

Eu tava pensando em fazer ‘‘modulos’’.

por exemplo:

A parte de html + servlet ia ser o modulo do usuario. ai ela acessava um metodo estatico que iniciava a parte de persistir no banco, e assim por diante

mas pensando eu to vendo que foi meio burra essa ideia

Se quer fazer módulos, crie uma API. A partir dela, construa a aplicação desktop, web, etc.
Sobre o erro: verifique se você declarou no pom.xml a dependência do mysql e se a mesma não está como provided.

Obrigado

Para quem está com o problema:

1- Verifique se o programa é web.
2- Verifique se falta algum .jar
3- Verifique o mapping da class no Hibernate