Cannot open connection- Struts + Hibernate?

Olá… não sei o que está acontecendo…

Estou tentando fazer umexemplo simples para inserir um campo no banco de dados…

Estou usando struts e hibernate.

Quando faço a persistência por uma classe (Main) da certo… mas quando vou fazer pela página da o seguinte erro…

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Cannot open connection
	org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:523)
	org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
	org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
	org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
	org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)

root cause

org.hibernate.exception.JDBCConnectionException: Cannot open connection
	org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:72)
	org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
	org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
	org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:327)
	org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:118)
	org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:127)
	org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
	org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1307)
	institutoSkill.ulisses.model.HibernateUtil.persiste(HibernateUtil.java:65)
	institutoSkill.ulisses.controler.action.InserirConcursoAction.execute(InserirConcursoAction.java:48)
	org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
	org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
	org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
	org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)

o que é isso ??

coloca o código aqui q vc ta usando para inicializar a sessao do hibernate e persistir o objeto.

Este é o codigo do minha classe que faz a persistência.

Abaixo tem a classe e o arquivo hbm.

public static void persiste( Object objeto ){ Session session = getSession(); Transaction tx = session.beginTransaction(); try{ System.out.println("Persiste - Salvando Registro"); tx.begin(); session.persist( objeto ); session.flush(); tx.commit(); //log.info( "Objeto salvo com Sucesso !! " ); }catch( Exception e ){ //log.info( "Holve problemas ao inserir o objeto: " + objeto.getClass().getName() ); System.out.println(e); System.out.println(e); e.printStackTrace(); tx.rollback(); }finally{ session.close(); } }

[code]public class Concurso implements Serializable{

private long id;

private String nome;

private Set cargos;


public Concurso(long id , String nome){
    setId(id);
    setNome(nome);
    
}

/** Creates a new instance of Concurso */
public Concurso() {
    this(0 , null);
}



public long getId() {
    return id;
}

public void setId(long id) {
    this.id = id;
}

public String getNome() {
    return nome;
}

public void setNome(String nome) {
    this.nome = nome;
}

public Set getCargos() {
    return cargos;
}

public void setCargos(Set cargos) {
    this.cargos = cargos;
}

}[/code]

[code]<hibernate-mapping>

&lt;class name=&quot;institutoSkill.ulisses.model.beans.Concurso&quot; table=&quot;CONCURSO&quot;&gt;
    
    &lt;id name=&quot;id&quot; column=&quot;id_concurso&quot; type=&quot;long&quot;&gt;
        &lt;generator class=&quot;sequence&quot; &gt;
            &lt;param name=&quot;sequence&quot;&gt;public.&quot;concurso_id_concurso_seq&quot;&lt;/param&gt;    
        &lt;/generator&gt;
    &lt;/id&gt;
    
    &lt;property name=&quot;nome&quot; type=&quot;string&quot; column=&quot;concurso_nome&quot; /&gt;
    
    &lt;set name=&quot;cargos&quot; table=&quot;CARGO&quot; inverse=&quot;true&quot;&gt;
        &lt;key column=&quot;ID_CONCURSO_FK&quot;/&gt;
        &lt;one-to-many class=&quot;institutoSkill.ulisses.model.beans.Cargo&quot;/&gt;
    &lt;/set&gt;
    
    
&lt;/class&gt;

</hibernate-mapping>[/code]

Acredito q nao seja problema de mapeamento, pois vc disse q sem ser pela web funciona. Como vc ta obtendo a sessao? Vc poderia por o metodo getSession ai pra nos? Aproveita e coloca o seu arquivo de configuração do hibernate ai tbm…

Este são outros dois metodos da minha classe hibernateUtil

[code] static {
try {
cfg = new Configuration();
sessionFactory = cfg.configure().buildSessionFactory();

    &#125; catch &#40;Throwable ex&#41; &#123;
        ex.printStackTrace&#40;&#41;;
        log.error&#40; &quot;Erro ao instanciar o objeto SessionFactory&quot; &#41;;
        throw new ExceptionInInitializerError&#40;ex&#41;;
    &#125;
&#125;


public static Session getSession&#40;&#41;throws HibernateException &#123;
    Session session = null;
    
    session = sessionFactory.openSession&#40;&#41;;
    
    return session;
&#125;[/code]

Este é o hibernate.cfg.xml

[code]<hibernate-configuration>

&lt;session-factory&gt;

    &lt;!-- Database connection settings --&gt;
    &lt;property name=&quot;connection.driver_class&quot;&gt;org.postgresql.Driver&lt;/property&gt;
    &lt;property name=&quot;connection.url&quot;&gt;jdbc&#58;postgresql&#58;//localhost&#58;5432/skill&lt;/property&gt;
    &lt;property name=&quot;connection.username&quot;&gt;postgres&lt;/property&gt;
    &lt;property name=&quot;connection.password&quot;&gt;postgres&lt;/property&gt;

    &lt;!-- JDBC connection pool &#40;use the built-in&#41; --&gt;
    &lt;property name=&quot;connection.pool_size&quot;&gt;1&lt;/property&gt;

    &lt;!-- SQL dialect --&gt;
    &lt;property name=&quot;dialect&quot;&gt;org.hibernate.dialect.PostgreSQLDialect&lt;/property&gt;
    
    &lt;!-- Enable Hibernate's automatic session context management
    &lt;property name=&quot;current_session_context_class&quot;&gt;thread&lt;/property&gt;
    --&gt;
    
    &lt;!-- Disable the second-level cache--&gt;
    &lt;property name=&quot;cache.provider_class&quot;&gt;org.hibernate.cache.NoCacheProvider&lt;/property&gt;
    
    &lt;property name=&quot;hibernate.cglib.use_reflection_optimizer&quot;&gt;true&lt;/property&gt;

    &lt;!-- Echo all executed SQL to stdout --&gt;
    &lt;property name=&quot;show_sql&quot;&gt;true&lt;/property&gt;

    &lt;mapping resource=&quot;institutoSkill/ulisses/model/beans/Concurso.hbm.xml&quot;/&gt;
   
    
&lt;/session-factory&gt;

</hibernate-configuration>[/code]