Olá pessoal,
estou desenvolvendo um e-commerce pra trabalho final de TCC, utilizando Eclipse helios, Struts 1, Hibernate 3, JBoss 5.1 com banco Postgres 8.4
no começo até tentei usar o pool de conexões do TomCat, JBoss he he sem chances só obtive erro em cima de erros!!! putz acho q já estou pegando raiva de Java! :evil:
"e bem que meus amigos me falaram, faça em .Net, usa o VS 2010 com MVC e tal é melhor que Java não precisa ficar “programando” em XML, mas a gente está sempre em busca de novos desafios, aí da nisso! he he
Bom, o certo é q estou tendo sérias dificuldades pra acessar via JDBC, não precisa ser usando pool, pode ser sem pool mesmo.
O engraçado é que criei uma simples aplicação usando as mesmas configurações da aplicação citada acima e funciona perfeitamente conectando via JDBC,
mas na minha aplicação principal, ou seja, ou seja, do TCC que está versionada no SVN não vai.
Atualmente estou recebendo mensagem de que tenho q ter uma JNDI configurada. mas eu não quero usar essa p****
Putz nem sei mais o q fazer. :roll:
Obs: o Driver JDBC do postgres está no dir do JBoss e no dir da aplicação
Bom desde já obrigado pessoal!
-------------- Depurando via JUnit obtive o seguinte Erro -------------------------------------------------
Teste método salvar
02:06:37 INFO [Version] Hibernate Annotations 3.5.0-Final
02:06:37 INFO [Environment] Hibernate 3.5.0-Final
02:06:37 INFO [Environment] hibernate.properties not found
02:06:37 INFO [Environment] Bytecode provider name : javassist
02:06:37 INFO [Environment] using JDK 1.4 java.sql.Timestamp handling
02:06:37 INFO [Version] Hibernate Commons Annotations 3.2.0.Final
02:06:37 INFO [Configuration] configuring from resource: /hibernate.cfg.xml
02:06:37 INFO [Configuration] Configuration resource: /hibernate.cfg.xml
02:06:37 INFO [Configuration] Configured SessionFactory:
02:06:37 INFO [HibernateSearchEventListenerRegister] Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
02:06:37 INFO [AnnotationConfiguration] Hibernate Validator not found: ignoring
02:06:37 INFO [DriverManagerConnectionProvider] Using Hibernate built-in connection pool (not for production use!)
02:06:37 INFO [DriverManagerConnectionProvider] Hibernate connection pool size: 20
02:06:37 INFO [DriverManagerConnectionProvider] autocommit mode: true
02:06:37 INFO [DriverManagerConnectionProvider] using driver: org.postgresql.Driver at URL: jdbc:postgresql:lizard
02:06:37 INFO [DriverManagerConnectionProvider] connection properties: {user=postgres, password=****, autocommit=true}
02:06:37 INFO [SettingsFactory] RDBMS: PostgreSQL, version: 8.4.4
02:06:37 INFO [SettingsFactory] JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 8.4 JDBC4 (build 701)
02:06:37 INFO [Dialect] Using dialect: org.hibernate.dialect.PostgreSQLDialect
02:06:37 INFO [JdbcSupportLoader] Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
02:06:37 INFO [TransactionFactoryFactory] Using default transaction strategy (direct JDBC transactions)
02:06:37 INFO [TransactionManagerLookupFactory] No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
02:06:37 INFO [SettingsFactory] Automatic flush during beforeCompletion(): disabled
02:06:37 INFO [SettingsFactory] Automatic session close at end of transaction: disabled
02:06:37 INFO [SettingsFactory] JDBC batch size: 15
02:06:37 INFO [SettingsFactory] JDBC batch updates for versioned data: disabled
02:06:37 INFO [SettingsFactory] Scrollable result sets: enabled
02:06:37 INFO [SettingsFactory] JDBC3 getGeneratedKeys(): enabled
02:06:37 INFO [SettingsFactory] Connection release mode: auto
02:06:37 INFO [SettingsFactory] Default batch fetch size: 1
02:06:37 INFO [SettingsFactory] Generate SQL with comments: disabled
02:06:37 INFO [SettingsFactory] Order SQL updates by primary key: disabled
02:06:37 INFO [SettingsFactory] Order SQL inserts for batching: disabled
02:06:37 INFO [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
02:06:37 INFO [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
02:06:37 INFO [SettingsFactory] Query language substitutions: {}
02:06:37 INFO [SettingsFactory] JPA-QL strict compliance: disabled
02:06:37 INFO [SettingsFactory] Second-level cache: enabled
02:06:37 INFO [SettingsFactory] Query cache: disabled
02:06:37 INFO [SettingsFactory] Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
02:06:37 INFO [SettingsFactory] Optimize cache for minimal puts: disabled
02:06:37 INFO [SettingsFactory] Structured second-level cache entries: disabled
02:06:37 INFO [SettingsFactory] Echoing all SQL to stdout
02:06:37 INFO [SettingsFactory] Statistics: disabled
02:06:37 INFO [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
02:06:37 INFO [SettingsFactory] Default entity-mode: pojo
02:06:37 INFO [SettingsFactory] Named query checking : enabled
02:06:37 INFO [SettingsFactory] Check Nullability in Core (should be disabled when Bean Validation is on): enabled
02:06:37 INFO [SessionFactoryImpl] building session factory
02:06:37 INFO [SessionFactoryObjectFactory] Factory name:
02:06:37 INFO [NamingHelper] JNDI InitialContext properties:{}
02:06:37 WARN [SessionFactoryObjectFactory] 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:75)
at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:113)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:376)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1385)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954)
at br.com.lizard.conexao.HibernateUtil.getSessionFactory(HibernateUtil.java:14)
at br.com.lizard.conexao.HibernateUtil.getSession(HibernateUtil.java:24)
at br.com.lizard.model.dao.Base.GenericDAO.getSession(GenericDAO.java:20)
at br.com.lizard.model.dao.Base.GenericDAO.executeAction(GenericDAO.java:44)
at br.com.lizard.model.dao.Base.GenericDAO.save(GenericDAO.java:25)
at br.com.lizard.teste.TestGenericDAO.testSave(TestGenericDAO.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
-------------------------------- 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”>org.postgresql.Driver</property>
<property name=“hibernate.connection.password”>postgres</property>
<property name=“hibernate.connection.url”>jdbc:postgresql:lizard</property>
<property name=“hibernate.connection.username”>postgres</property>
<property name=“hibernate.dialect”>org.hibernate.dialect.PostgreSQLDialect</property>
<property name=“hibernate.connection.autocommit”>true</property>
<property name=“hibernate.show_sql”>true</property>
<property name=“hibernate.use_sql_comments”>false</property>
<property name=“hibernate.format_sql”>true</property>
</session-factory>
</hibernate-configuration>
-------------------- Classe de conexão ----------------------------------------------------------
package br.com.lizard.conexao;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
public class HibernateUtil {
private static SessionFactory sessionFactory;
private static SessionFactory getSessionFactory() {
try {
if (sessionFactory == null)
sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
return sessionFactory;
} catch (Throwable e) {
System.out.println("A criação do Session Factory falhou!");
System.out.println(e.toString());
}
return sessionFactory;
}
public static Session getSession() {
return getSessionFactory().getCurrentSession();
}
}