Hibernate: Could not bind factory to JNDI

Estou estudando hibernate, criei uma aplicacao bem simples que esta funcionando, mas esta mostrando alguns avisos que eu queria consertar.

olhae a saida do log

init: deps-module-jar: deps-ear-jar: deps-jar: compile-single: run-main: 20:19:56,809 WARN SessionFactoryObjectFactory:98 - Could not bind factory to JNDI javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645) at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288) at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325) at javax.naming.InitialContext.getNameParser(InitialContext.java:480) at org.hibernate.util.NamingHelper.bind(NamingHelper.java:52) at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:90) at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:306) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294) at persistance.HibernateUtil.<clinit>(HibernateUtil.java:21) at hello.HelloWorld.main(HelloWorld.java:22) Hibernate: select max(MESSAGE_ID) from MESSAGE Hibernate: insert into MESSAGE (MESSAGE_TEXT, NEXT_MESSAGE_ID, MESSAGE_ID) values (?, ?, ?) Hibernate: select message0_.MESSAGE_ID as MESSAGE1_0_, message0_.MESSAGE_TEXT as MESSAGE2_0_, message0_.NEXT_MESSAGE_ID as NEXT3_0_ from MESSAGE message0_ order by message0_.MESSAGE_TEXT asc 16 message(s) found: Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World 20:19:57,168 WARN SessionFactoryObjectFactory:123 - Could not unbind factory from JNDI javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645) at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288) at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325) at javax.naming.InitialContext.unbind(InitialContext.java:416) at org.hibernate.impl.SessionFactoryObjectFactory.removeInstance(SessionFactoryObjectFactory.java:116) at org.hibernate.impl.SessionFactoryImpl.close(SessionFactoryImpl.java:806) at persistance.HibernateUtil.shutdown(HibernateUtil.java:38) at hello.HelloWorld.main(HelloWorld.java:44) BUILD SUCCESSFUL (total time: 2 seconds)

aqui as classes:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hello;

import java.util.Iterator;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction;
import persistance.HibernateUtil;

/**
 *
 * @author Bernardo
 */
public class HelloWorld {

    public static void main(String[] args) {
        
        // First unit of work
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        Message message = new Message("Hello World");
        session.save(message);
        tx.commit();
        session.close();
        
        // Second unit of work
        Session newSession = HibernateUtil.getSessionFactory().openSession();
        Transaction newTransaction = newSession.beginTransaction();
        List messages = newSession.createQuery("from Message m order by m.text asc").list();
        System.out.println(messages.size() + " message(s) found:");

        for (Iterator iter = messages.iterator();iter.hasNext();) {
            Message loadedMsg = (Message) iter.next();
            System.out.println(loadedMsg.getText());
        }
        
        newTransaction.commit();
        newSession.close();
        
        // Shutting down the application
        HibernateUtil.shutdown();
    }

    private HelloWorld() {
    }

}

[code]/*

  • To change this template, choose Tools | Templates
  • and open the template in the editor.
    */
    package hello;

/**
*

  • @author Bernardo
    */
    public class Message {

    private Long id;
    private String text;
    private Message nextMessage;

    Message() {
    }

    /**
    *

    • @param text
      */
      public Message(String text) {
      this.text = text;
      }

    /**
    *

    • @return
      */
      public Long getId() {
      return id;
      }

    /**
    *

    • @param id
      */
      public void setId(Long id) {
      this.id = id;
      }

    /**
    *

    • @return
      */
      public String getText() {
      return text;
      }

    /**
    *

    • @param text
      */
      public void setText(String text) {
      this.text = text;
      }

    /**
    *

    • @return
      */
      public Message getNextMessage() {
      return nextMessage;
      }

    /**
    *

    • @param nextMessage
      */
      public void setNextMessage(Message nextMessage) {
      this.nextMessage = nextMessage;
      }

}
[/code]

aqui os arquivos de configuracao:

<?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 name="session">
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect
        </property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver
        </property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernate
        </property>
        <property name="hibernate.connection.username">root
        </property>
        <property name="hibernate.connection.password">senha
        </property>
    
        <!-- Show and print nice SQL on stdout -->
        <property name="show_sql">true</property>
        <property name="format_sql">true</property>
        
        <!-- List of XML mapping files -->
        <mapping resource="hello/Message.hbm.xml"/>
        
    </session-factory>
</hibernate-configuration>

[code]<?xml version="1.0"?>

[/code]

[code]hibernate.c3p0.min_size 5
hibernate.c3p0.max_size 20
hibernate.c3p0.timeout 300
hibernate.c3p0.max_statements 50
hibernate.c3p0.idle_test_period 3000
hibernate.c3p0.acquire_increment 2
hibernate.c3p0.validate false

hibernate.format_sql true

hibernate.max_fetch_depth 1

hibernate.jdbc.batch_versioned_data true

hibernate.jdbc.use_streams_for_binary true

hibernate.cache.region_prefix hibernate.test

hibernate.cache.provider_class org.hibernate.cache.HashtableCacheProvider
[/code]

troca o <session-factory name=“session”> por <session-factory> no arquivo de configuração.

abraços

[quote=HumbertoMoura]troca o <session-factory name=“session”> por <session-factory> no arquivo de configuração.

abraços[/quote]

Valeu cara!!! Salvou minha vida!!!