Blz galera, estou ficando quase louco com esse problema. Acredito que esteja faltando algum detalhe muito pequeno que eu não percebi.
Eu usei o Hibernate Tools ( Eclipse ) para gerar todos os arquivos de configuração e a coisa não vai. Se alguem puder me dar uma força agradeço.
O erro é este:
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
Esse é o Log completo que esta sendo reportado
28/04/2006 08:26:31 org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.1.2
28/04/2006 08:26:31 org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
28/04/2006 08:26:31 org.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
28/04/2006 08:26:31 org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
28/04/2006 08:26:31 org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
28/04/2006 08:26:31 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
28/04/2006 08:26:31 org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource: br/com/sygnux/model/Usuarios.hbm.xml
28/04/2006 08:26:32 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: br.com.sygnux.model.Usuarios -> USUARIOS
28/04/2006 08:26:32 org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource: br/com/sygnux/model/Clientes.hbm.xml
28/04/2006 08:26:32 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: br.com.sygnux.model.Clientes -> CLIENTES
28/04/2006 08:26:32 org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource: br/com/sygnux/model/Contasreceber.hbm.xml
28/04/2006 08:26:32 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: br.com.sygnux.model.Contasreceber -> CONTASRECEBER
28/04/2006 08:26:32 org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource: br/com/sygnux/model/Contratos.hbm.xml
28/04/2006 08:26:32 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: br.com.sygnux.model.Contratos -> CONTRATOS
28/04/2006 08:26:32 org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: java:comp/env/hibernate/SessionFactory
28/04/2006 08:26:32 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
28/04/2006 08:26:32 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
28/04/2006 08:26:32 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
28/04/2006 08:26:32 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: org.firebirdsql.jdbc.FBDriver at URL: jdbc:firebirdsql://localhost:3050/D:/Bases/SYGNUX.FDB
28/04/2006 08:26:32 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=sysdba, password=****}
28/04/2006 08:26:32 org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: Firebird 1.5, version: WI-V1.5.3.4842 Firebird 1.5,WI-V1.5.3.4842 Firebird 1.5/tcp (sygnux)/P10
28/04/2006 08:26:32 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: JayBird JCA/JDBC driver, version: 2.0
28/04/2006 08:26:32 org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.FirebirdDialect
28/04/2006 08:26:32 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
28/04/2006 08:26:32 org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
28/04/2006 08:26:32 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
28/04/2006 08:26:32 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
28/04/2006 08:26:32 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
28/04/2006 08:26:32 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
28/04/2006 08:26:32 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
28/04/2006 08:26:32 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
28/04/2006 08:26:32 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
28/04/2006 08:26:32 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
28/04/2006 08:26:32 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
28/04/2006 08:26:32 org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
28/04/2006 08:26:32 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
28/04/2006 08:26:32 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
28/04/2006 08:26:32 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
28/04/2006 08:26:32 org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.EhCacheProvider
28/04/2006 08:26:32 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
28/04/2006 08:26:32 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
28/04/2006 08:26:32 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
28/04/2006 08:26:32 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
28/04/2006 08:26:32 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
28/04/2006 08:26:32 org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
28/04/2006 08:26:32 net.sf.ehcache.config.Configurator configure
WARNING: No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/D:/Java/Sygnux/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
28/04/2006 08:26:33 org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Factory name: java:comp/env/hibernate/SessionFactory
28/04/2006 08:26:33 org.hibernate.util.NamingHelper getInitialContext
INFO: JNDI InitialContext properties:{}
28/04/2006 08:26:33 org.hibernate.impl.SessionFactoryObjectFactory addInstance
WARNING: 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(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getNameParser(Unknown Source)
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:290)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1176)
at Principal.main(Principal.java:16)
Exception in thread "main" java.lang.NoClassDefFoundError: javax/transaction/Synchronization
at org.hibernate.impl.SessionImpl.<init>(SessionImpl.java:266)
at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:436)
at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:460)
at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:468)
at Principal.main(Principal.java:18)
E esses são os arquivos de configuração gerado pelo HibernateTools
<?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="java:comp/env/hibernate/SessionFactory">
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">org.firebirdsql.jdbc.FBDriver</property>
<property name="hibernate.connection.password">xxxxxx</property>
<property name="hibernate.connection.url">jdbc:firebirdsql://localhost:3050/D:/Bases/SYGNUX.FDB</property>
<property name="hibernate.connection.username">sysdba</property>
<property name="hibernate.dialect">org.hibernate.dialect.FirebirdDialect</property>
<mapping resource="br/com/sygnux/model/Usuarios.hbm.xml" />
<mapping resource="br/com/sygnux/model/Clientes.hbm.xml" />
<mapping resource="br/com/sygnux/model/Contasreceber.hbm.xml" />
<mapping resource="br/com/sygnux/model/Contratos.hbm.xml" />
</session-factory>
</hibernate-configuration>
Um dos arquivos de Mapeamento gerado pelo Hibernate Tools
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 28/04/2006 08:17:49 by Hibernate Tools 3.1.0.beta5 -->
<hibernate-mapping>
<class name="br.com.sygnux.model.Usuarios" table="USUARIOS">
<id name="usuId" type="int">
<column name="USU_ID" />
<generator class="assigned" />
</id>
<property name="usuLogin" type="string">
<column name="USU_LOGIN" length="10" not-null="true" unique="true" />
</property>
<property name="usuPassword" type="string">
<column name="USU_PASSWORD" length="10" not-null="true" />
</property>
<property name="usuNome" type="string">
<column name="USU_NOME" length="50" />
</property>
<property name="usuAtivo" type="string">
<column name="USU_ATIVO" length="1" />
</property>
</class>
</hibernate-mapping>
E por fim o arquivo de teste que eu estou usando para “tentar” inserir os dados
import br.com.sygnux.model.*;
import org.hibernate.*;
import org.hibernate.cfg.*;
public class Principal {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
//SessionFactory deve ser criado uma única vez durante a execução
//da aplicação
SessionFactory sf = new Configuration().configure("/hibernate.cfg.xml").buildSessionFactory();
Session session = sf.openSession(); //Abre sessão
Transaction tx = session.beginTransaction(); //Cria transação
Usuarios usuario = new Usuarios();
usuario.setUsuAtivo("S") ;
usuario.setUsuNome("Teste");
usuario.setUsuLogin("Teste");
usuario.setUsuPassword("Teste");
session.save(usuario);
tx.commit();
session.close() ;
}catch(HibernateException e1){
e1.printStackTrace();
}catch(Exception e2){
e2.printStackTrace();
}
}
}
Valeu !!!