Boa tarde, estou inciando deenvolvimento java profissional, e este é o meu primeiro tópico neste fórum. Pena que seja em uma situação de desespero =)
Eu desenvolvi uma aplicação, relativamente, simples baseado nas apostilas do curso fj-21 e fj-28 da Caelum, utilizando VRaptor e Hibernate (com Hibernate Annotations).
A aplicação funciona sem nenhum problema na minha base (Tomcat 6.0.13, conexao jdbc diretamente), mas na hospedagem - Locaweb (Tomcat 5.5) com JVM dedicada - não funciona.
Na Locaweb, utilizando jdbc diretamente, a aplicação é bastaaaaante instável. Entretanto, desde quarta-feira, configuraram o JNDI para que eu possa utilizar, mas nada funciona com ele.
Segue o meu hibernate.properties:
hibernate.dialect = org.hibernate.dialect.MySQLDialect
hibernate.connection.datasource java:comp/env/jdbc/clientesocyal
hibernate.show_sql = false
Segue o meu HibernateConf:
package br.com.segurotorcedor.conf ;
import org.hibernate.Session ;
import org.hibernate.SessionFactory ;
import org.hibernate.cfg.AnnotationConfiguration ;
import br.com.segurotorcedor.modelo.BrindeSorteio ;
import br.com.segurotorcedor.modelo.Cliente ;
import br.com.segurotorcedor.modelo.Clube ;
import br.com.segurotorcedor.modelo.Link ;
import br.com.segurotorcedor.modelo.Noticia ;
import br.com.segurotorcedor.modelo.ParametrosGerais ;
import br.com.segurotorcedor.modelo.PromocaoSorteio ;
public class HibernateConf {
private static SessionFactory factory ;
static {
AnnotationConfiguration cfg = new AnnotationConfiguration ();
cfg . addAnnotatedClass ( BrindeSorteio . class );
cfg . addAnnotatedClass ( Cliente . class );
cfg . addAnnotatedClass ( Clube . class );
cfg . addAnnotatedClass ( Link . class );
cfg . addAnnotatedClass ( Noticia . class );
cfg . addAnnotatedClass ( PromocaoSorteio . class );
cfg . addAnnotatedClass ( ParametrosGerais . class );
factory = cfg . buildSessionFactory ();
System . out . println ( "rodou hibernateConf" );
}
public static Session getSession () {
return factory . openSession ();
}
}
Eu criei um pequeno jsp de teste, que pega a sessao diretamente do HibernateConf. Segue:
<% @page import = "br.com.segurotorcedor.modelo.ParametrosGerais" %>
<% @page import = "br.com.segurotorcedor.dao.ParametrosGeraisDAO" %>
<% @page import = "org.hibernate.Transaction" %>
<% @page import = "br.com.segurotorcedor.conf.HibernateConf" %>
<% @page import = "org.hibernate.Session" %>
<%
// Class . forName ( "br.com.segurotorcedor.conf.HibernateConf" );
Session session2 = HibernateConf . getSession ();
Transaction transaction = session2 . beginTransaction ();
ParametrosGeraisDAO dao = new ParametrosGeraisDAO ( session2 );
long l = 1 ;
ParametrosGerais p = dao . carregar ( l );
response . getWriter () . write ( p . getStrAdminLogin ());
transaction . commit ();
O erro sempre acontece na linha onde é chamado o HibernateConf.getSession(). Tanto neste jsp de teste, qnt no DAOFactory qnd tento acessar a minha aplicação.
Chamando este jsp, o seguinte erro é apresentado (desculpa se tem coisa desnecessária, mas não estou conseguindo filtar mto bem esse log):
2007 - 07 - 14 13 : 56 : 31 , 052 [ TP-Processor14 ] INFO org . hibernate . util . NamingHelper - JNDI InitialContext properties : {}
2007 - 07 - 14 13 : 56 : 31 , 061 [ TP-Processor14 ] FATAL org . hibernate . connection . DatasourceConnectionProvider - Could not find datasource : java : comp / env / jdbc / clientesocyal
javax . naming . NameNotFoundException : Name clientesocyal is not bound in this Context
at org . apache . naming . NamingContext . lookup ( NamingContext . java : 769 )
at org . apache . naming . NamingContext . lookup ( NamingContext . java : 139 )
at org . apache . naming . NamingContext . lookup ( NamingContext . java : 780 )
at org . apache . naming . NamingContext . lookup ( NamingContext . java : 139 )
at org . apache . naming . NamingContext . lookup ( NamingContext . java : 780 )
at org . apache . naming . NamingContext . lookup ( NamingContext . java : 139 )
at org . apache . naming . NamingContext . lookup ( NamingContext . java : 780 )
at org . apache . naming . NamingContext . lookup ( NamingContext . java : 152 )
at org . apache . naming . SelectorContext . lookup ( SelectorContext . java : 136 )
at javax . naming . InitialContext . lookup ( InitialContext . java : 351 )
at org . hibernate . connection . DatasourceConnectionProvider . configure ( DatasourceConnectionProvider . java : 52 )
at org . hibernate . connection . ConnectionProviderFactory . newConnectionProvider ( ConnectionProviderFactory . java : 124 )
at org . hibernate . connection . ConnectionProviderFactory . newConnectionProvider ( ConnectionProviderFactory . java : 56 )
at org . hibernate . cfg . SettingsFactory . createConnectionProvider ( SettingsFactory . java : 414 )
at org . hibernate . cfg . SettingsFactory . buildSettings ( SettingsFactory . java : 62 )
at org . hibernate . cfg . Configuration . buildSettings ( Configuration . java : 2009 )
at org . hibernate . cfg . Configuration . buildSessionFactory ( Configuration . java : 1292 )
at org . hibernate . cfg . AnnotationConfiguration . buildSessionFactory ( AnnotationConfiguration . java : 915 )
at br . com . segurotorcedor . conf . HibernateConf .( HibernateConf . java : 33 )
at org . apache . jsp . testeHibernate_jsp . _jspService ( testeHibernate_jsp . java : 56 )
at org . apache . jasper . runtime . HttpJspBase . service ( HttpJspBase . java : 97 )
at javax . servlet . http . HttpServlet . service ( HttpServlet . java : 802 )
at org . apache . jasper . servlet . JspServletWrapper . service ( JspServletWrapper . java : 332 )
at org . apache . jasper . servlet . JspServlet . serviceJspFile ( JspServlet . java : 314 )
at org . apache . jasper . servlet . JspServlet . service ( JspServlet . java : 264 )
at javax . servlet . http . HttpServlet . service ( HttpServlet . java : 802 )
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 252 )
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 173 )
at org . apache . catalina . core . StandardWrapperValve . invoke ( StandardWrapperValve . java : 213 )
at org . apache . catalina . core . StandardContextValve . invoke ( StandardContextValve . java : 178 )
at org . apache . catalina . core . StandardHostValve . invoke ( StandardHostValve . java : 126 )
at org . apache . catalina . valves . ErrorReportValve . invoke ( ErrorReportValve . java : 105 )
at org . apache . catalina . core . StandardEngineValve . invoke ( StandardEngineValve . java : 107 )
at br . com . locaweb . tomcat . LocaWebValve . invoke ( LocaWebValve . java : 101 )
at org . apache . catalina . connector . CoyoteAdapter . service ( CoyoteAdapter . java : 148 )
at org . apache . jk . server . JkCoyoteHandler . invoke ( JkCoyoteHandler . java : 199 )
at org . apache . jk . common . HandlerRequest . invoke ( HandlerRequest . java : 282 )
at org . apache . jk . common . ChannelSocket . invoke ( ChannelSocket . java : 754 )
at org . apache . jk . common . ChannelSocket . processConnection ( ChannelSocket . java : 684 )
at org . apache . jk . common . ChannelSocket $ SocketConnection . runIt ( ChannelSocket . java : 876 )
at org . apache . tomcat . util . threads . ThreadPool $ ControlRunnable . run ( ThreadPool . java : 684 )
at java . lang . Thread . run ( Thread . java : 595 )
2007 - 07 - 14 13 : 56 : 31 , 093 [ TP-Processor14 ] ERROR org . apache . catalina . core . ContainerBase . [ Standalone ] . [ clientesocyal.tempsite.ws ] . [ /segurotorcedor ] . [ jsp ] - Servlet . service () for servlet jsp threw exception
java . lang . ExceptionInInitializerError
at org . apache . jsp . testeHibernate_jsp . _jspService ( testeHibernate_jsp . java : 56 )
at org . apache . jasper . runtime . HttpJspBase . service ( HttpJspBase . java : 97 )
at javax . servlet . http . HttpServlet . service ( HttpServlet . java : 802 )
at org . apache . jasper . servlet . JspServletWrapper . service ( JspServletWrapper . java : 332 )
at org . apache . jasper . servlet . JspServlet . serviceJspFile ( JspServlet . java : 314 )
at org . apache . jasper . servlet . JspServlet . service ( JspServlet . java : 264 )
at javax . servlet . http . HttpServlet . service ( HttpServlet . java : 802 )
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 252 )
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 173 )
at org . apache . catalina . core . StandardWrapperValve . invoke ( StandardWrapperValve . java : 213 )
at org . apache . catalina . core . StandardContextValve . invoke ( StandardContextValve . java : 178 )
at org . apache . catalina . core . StandardHostValve . invoke ( StandardHostValve . java : 126 )
at org . apache . catalina . valves . ErrorReportValve . invoke ( ErrorReportValve . java : 105 )
at org . apache . catalina . core . StandardEngineValve . invoke ( StandardEngineValve . java : 107 )
at br . com . locaweb . tomcat . LocaWebValve . invoke ( LocaWebValve . java : 101 )
at org . apache . catalina . connector . CoyoteAdapter . service ( CoyoteAdapter . java : 148 )
at org . apache . jk . server . JkCoyoteHandler . invoke ( JkCoyoteHandler . java : 199 )
at org . apache . jk . common . HandlerRequest . invoke ( HandlerRequest . java : 282 )
at org . apache . jk . common . ChannelSocket . invoke ( ChannelSocket . java : 754 )
at org . apache . jk . common . ChannelSocket . processConnection ( ChannelSocket . java : 684 )
at org . apache . jk . common . ChannelSocket $ SocketConnection . runIt ( ChannelSocket . java : 876 )
at org . apache . tomcat . util . threads . ThreadPool $ ControlRunnable . run ( ThreadPool . java : 684 )
at java . lang . Thread . run ( Thread . java : 595 )
Caused by : org . hibernate . HibernateException : Could not find datasource
at org . hibernate . connection . DatasourceConnectionProvider . configure ( DatasourceConnectionProvider . java : 56 )
at org . hibernate . connection . ConnectionProviderFactory . newConnectionProvider ( ConnectionProviderFactory . java : 124 )
at org . hibernate . connection . ConnectionProviderFactory . newConnectionProvider ( ConnectionProviderFactory . java : 56 )
at org . hibernate . cfg . SettingsFactory . createConnectionProvider ( SettingsFactory . java : 414 )
at org . hibernate . cfg . SettingsFactory . buildSettings ( SettingsFactory . java : 62 )
at org . hibernate . cfg . Configuration . buildSettings ( Configuration . java : 2009 )
at org . hibernate . cfg . Configuration . buildSessionFactory ( Configuration . java : 1292 )
at org . hibernate . cfg . AnnotationConfiguration . buildSessionFactory ( AnnotationConfiguration . java : 915 )
at br . com . segurotorcedor . conf . HibernateConf .( HibernateConf . java : 33 )
… 23 more
Caused by : javax . naming . NameNotFoundException : Name clientesocyal is not bound in this Context
at org . apache . naming . NamingContext . lookup ( NamingContext . java : 769 )
at org . apache . naming . NamingContext . lookup ( NamingContext . java : 139 )
at org . apache . naming . NamingContext . lookup ( NamingContext . java : 780 )
at org . apache . naming . NamingContext . lookup ( NamingContext . java : 139 )
at org . apache . naming . NamingContext . lookup ( NamingContext . java : 780 )
at org . apache . naming . NamingContext . lookup ( NamingContext . java : 139 )
at org . apache . naming . NamingContext . lookup ( NamingContext . java : 780 )
at org . apache . naming . NamingContext . lookup ( NamingContext . java : 152 )
at org . apache . naming . SelectorContext . lookup ( SelectorContext . java : 136 )
at javax . naming . InitialContext . lookup ( InitialContext . java : 351 )
at org . hibernate . connection . DatasourceConnectionProvider . configure ( DatasourceConnectionProvider . java : 52 )
… 31 more
2007 - 07 - 14 13 : 56 : 31 , 093 [ TP-Processor14 ] ERROR org . apache . catalina . core . ContainerBase . [ Standalone ] . [ clientesocyal.tempsite.ws ] . [ /segurotorcedor ] . [ jsp ] - Servlet . service () for servlet jsp threw exception
java . lang . ExceptionInInitializerError
at org . apache . jsp . testeHibernate_jsp . _jspService ( testeHibernate_jsp . java : 56 )
at org . apache . jasper . runtime . HttpJspBase . service ( HttpJspBase . java : 97 )
at javax . servlet . http . HttpServlet . service ( HttpServlet . java : 802 )
at org . apache . jasper . servlet . JspServletWrapper . service ( JspServletWrapper . java : 332 )
at org . apache . jasper . servlet . JspServlet . serviceJspFile ( JspServlet . java : 314 )
at org . apache . jasper . servlet . JspServlet . service ( JspServlet . java : 264 )
at javax . servlet . http . HttpServlet . service ( HttpServlet . java : 802 )
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 252 )
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 173 )
at org . apache . catalina . core . StandardWrapperValve . invoke ( StandardWrapperValve . java : 213 )
at org . apache . catalina . core . StandardContextValve . invoke ( StandardContextValve . java : 178 )
at org . apache . catalina . core . StandardHostValve . invoke ( StandardHostValve . java : 126 )
at org . apache . catalina . valves . ErrorReportValve . invoke ( ErrorReportValve . java : 105 )
at org . apache . catalina . core . StandardEngineValve . invoke ( StandardEngineValve . java : 107 )
at br . com . locaweb . tomcat . LocaWebValve . invoke ( LocaWebValve . java : 101 )
at org . apache . catalina . connector . CoyoteAdapter . service ( CoyoteAdapter . java : 148 )
at org . apache . jk . server . JkCoyoteHandler . invoke ( JkCoyoteHandler . java : 199 )
at org . apache . jk . common . HandlerRequest . invoke ( HandlerRequest . java : 282 )
at org . apache . jk . common . ChannelSocket . invoke ( ChannelSocket . java : 754 )
at org . apache . jk . common . ChannelSocket . processConnection ( ChannelSocket . java : 684 )
at org . apache . jk . common . ChannelSocket $ SocketConnection . runIt ( ChannelSocket . java : 876 )
at org . apache . tomcat . util . threads . ThreadPool $ ControlRunnable . run ( ThreadPool . java : 684 )
at java . lang . Thread . run ( Thread . java : 595 )
Caused by : org . hibernate . HibernateException : Could not find datasource
at org . hibernate . connection . DatasourceConnectionProvider . configure ( DatasourceConnectionProvider . java : 56 )
at org . hibernate . connection . ConnectionProviderFactory . newConnectionProvider ( ConnectionProviderFactory . java : 124 )
at org . hibernate . connection . ConnectionProviderFactory . newConnectionProvider ( ConnectionProviderFactory . java : 56 )
at org . hibernate . cfg . SettingsFactory . createConnectionProvider ( SettingsFactory . java : 414 )
at org . hibernate . cfg . SettingsFactory . buildSettings ( SettingsFactory . java : 62 )
at org . hibernate . cfg . Configuration . buildSettings ( Configuration . java : 2009 )
at org . hibernate . cfg . Configuration . buildSessionFactory ( Configuration . java : 1292 )
at org . hibernate . cfg . AnnotationConfiguration . buildSessionFactory ( AnnotationConfiguration . java : 915 )
at br . com . segurotorcedor . conf . HibernateConf .( HibernateConf . java : 33 )
… 23 more
Caused by : javax . naming . NameNotFoundException : Name clientesocyal is not bound in this Context
at org . apache . naming . NamingContext . lookup ( NamingContext . java : 769 )
at org . apache . naming . NamingContext . lookup ( NamingContext . java : 139 )
at org . apache . naming . NamingContext . lookup ( NamingContext . java : 780 )
at org . apache . naming . NamingContext . lookup ( NamingContext . java : 139 )
at org . apache . naming . NamingContext . lookup ( NamingContext . java : 780 )
at org . apache . naming . NamingContext . lookup ( NamingContext . java : 139 )
at org . apache . naming . NamingContext . lookup ( NamingContext . java : 780 )
at org . apache . naming . NamingContext . lookup ( NamingContext . java : 152 )
at org . apache . naming . SelectorContext . lookup ( SelectorContext . java : 136 )
at javax . naming . InitialContext . lookup ( InitialContext . java : 351 )
at org . hibernate . connection . DatasourceConnectionProvider . configure ( DatasourceConnectionProvider . java : 52 )
… 31 more
Já abri diversos chamados no suporte dessa empresa, mas eles insistem em afirmar que o erro é na minha aplicação, pois como criam um jsp para o teste do jndi (sem hibernate, claro) funciona, tanto no contexto add, qnt no principal.
Segue o testeJNDI.jsp:
<% @page language = "java" import = "java.io.*,java.sql.*,javax.sql.*,javax.naming.*" %>
<html>
<head>
<title> JNDI</title>
</head>
<body>
<%
Connection conexao ;
ResultSet rs ;
DataSource ds ;
try {
Context context = new InitialContext ();
Context lautx = ( Context ) context . lookup ( "java:comp/env" );
ds = ( DataSource ) lautx . lookup ( "jdbc/clientesocyal" );
conexao = ds . getConnection ();
out . write ( "Conectado via JNDI!<br><br>" );
Statement stmt = conexao . createStatement ();
conexao . close ();
} catch ( SQLException sqle ) {
out . write ( "<======= OCORREU UMA EXCEPTION - VERIFICAR =======><br><br><br>" + sqle );
sqle . printStackTrace ();
} finally {
}
%>
</body>
</html>
Alguém já passou por problema parecido e pode me ajudar? Precisam de mais informações sobre minha aplicação? Já estou desesperado, pois não sei mais o que fazer para resolver esse problema.
Obrigado.