em meu projeto eu estava usando o Mysql e estava funcionando sem problemas, resolvi mudar o mesmo projeto e acessar o banco firebird (não foi escolha minha), sendo que depois que mudei ele esta dando um erro que não consigo resolver
- Coloquei no lib e no classpath do projeto o drive jaybird
-O banco esta em um servido que vai ficar separado da aplicação.
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration><session-factory><!-- local connection properties --><propertyname="connection.driver_class">org.firebirdsql.jdbc.FBDriver</property><propertyname="connection.url">jdbc:firebirdsql:172.17.1.21/databases/BANCOZETA.FDB</property><propertyname="connection.username">root3</property><propertyname="connection.password">lsecret45</property><propertyname="dialect">org.hibernate.dialect.FirebirdDialect</property><propertyname="hibernate.show_sql">true</property><propertyname="hibernate.hbm2ddl.auto">create</property><propertyname="current_session_context_class">thread</property><propertyname="cache.provider_class">org.hibernate.cache.NoCacheProvider</property><propertyname="show_sql">true</property></session-factory></hibernate-configuration>
Essa classe é só para testar a conexão que não esta funcionando
importorg.hibernate.Session;importbr.com.caelum.tarefas.modelo.Ctec_imoveis;importbr.com.caelum.hibernate.dao.Ctec_imoveisDAO;publicclassTestaCtec_imoveisDAO{publicstaticvoidmain(String[]args){Sessionsession=newHibernateUtil().getSession();Ctec_imoveisDAOctec_imoveisDao=newCtec_imoveisDAO(session);System.out.println("*****Listando Tudo*******");for(Ctec_imoveisp:ctec_imoveisDao.listaTudo()){System.out.println(p.getI000());}System.out.println("*****Listando Paginado*******");for(Ctec_imoveisp:ctec_imoveisDao.pagina(2,3)){System.out.println(p.getI000());}System.out.println("*****Preços maiores que*******");for(Ctec_imoveisp:ctec_imoveisDao.precoMaiorQue(2.10)){System.out.println(p.getI000());}}}
O erro:
Exception in thread "main" java.lang.ExceptionInInitializerError
at br.com.caelum.hibernate.TestaCtec_imoveisDAO.main(TestaCtec_imoveisDAO.java:15)
Caused by: org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection available
at org.hibernate.dialect.resolver.DialectFactory.buildDialect(DialectFactory.java:107)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:142)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2163)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2159)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1383)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954)
at br.com.caelum.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:14)
... 1 more
em meu projeto eu estava usando o Mysql e estava funcionando sem problemas, resolvi mudar o mesmo projeto e acessar o banco firebird (não foi escolha minha), sendo que depois que mudei ele esta dando um erro que não consigo resolver
- Coloquei no lib e no classpath do projeto o drive jaybird
-O banco esta em um servido que vai ficar separado da aplicação.
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration><session-factory><!-- local connection properties --><propertyname="connection.driver_class">org.firebirdsql.jdbc.FBDriver</property><propertyname="connection.url">jdbc:firebirdsql:172.17.1.21/databases/BANCOZETA.FDB</property><propertyname="connection.username">root3</property><propertyname="connection.password">lsecre45</property><propertyname="dialect">org.hibernate.dialect.FirebirdDialect</property><propertyname="hibernate.show_sql">true</property><propertyname="hibernate.hbm2ddl.auto">create</property><propertyname="current_session_context_class">thread</property><propertyname="cache.provider_class">org.hibernate.cache.NoCacheProvider</property><propertyname="show_sql">true</property></session-factory></hibernate-configuration>
Essa classe é só para testar a conexão que não esta funcionando
importorg.hibernate.Session;importbr.com.caelum.tarefas.modelo.Ctec_imoveis;importbr.com.caelum.hibernate.dao.Ctec_imoveisDAO;publicclassTestaCtec_imoveisDAO{publicstaticvoidmain(String[]args){Sessionsession=newHibernateUtil().getSession();Ctec_imoveisDAOctec_imoveisDao=newCtec_imoveisDAO(session);System.out.println("*****Listando Tudo*******");for(Ctec_imoveisp:ctec_imoveisDao.listaTudo()){System.out.println(p.getI000());}System.out.println("*****Listando Paginado*******");for(Ctec_imoveisp:ctec_imoveisDao.pagina(2,3)){System.out.println(p.getI000());}System.out.println("*****Preços maiores que*******");for(Ctec_imoveisp:ctec_imoveisDao.precoMaiorQue(2.10)){System.out.println(p.getI000());}}}
O erro:
Exception in thread "main" java.lang.ExceptionInInitializerError
at br.com.caelum.hibernate.TestaCtec_imoveisDAO.main(TestaCtec_imoveisDAO.java:15)
Caused by: org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection available
at org.hibernate.dialect.resolver.DialectFactory.buildDialect(DialectFactory.java:107)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:142)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2163)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2159)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1383)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954)
at br.com.caelum.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:14)
... 1 more
Por favor me ajudem, beijo a todos
romarcio
Faz um teste, troca seu arquivo hibernate.cfg.xml por um hibernate.properties.
Sempre que vejo problemas relacionados a hibernate.dialect, essa troca acaba resolvendo.
Não sei se é algum tipo de bug em alguma versão do hibernate, mas faz essa troca e depois diz se resolveu.
natasha
Olá obrigada pela resposta.
coloquei o hibernate.properties e apaguei o hibernate.cfg.xml
o erro mudou, desconfio que é a URL como banco, estou fazendo do jeito certo?
*****Listando Tudo*******
Exception in thread "main" org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1596)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
at org.hibernate.loader.Loader.doList(Loader.java:2294)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2172)
at org.hibernate.loader.Loader.list(Loader.java:2167)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1706)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347)
at br.com.caelum.hibernate.dao.Ctec_imoveisDAO.listaTudo(Ctec_imoveisDAO.java:36)
at br.com.caelum.hibernate.TestaCtec_imoveisDAO.main(TestaCtec_imoveisDAO.java:16)
Caused by: org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544472. Your user name and password are not defined. Ask your database administrator to set up a Firebird login.
Reason: Your user name and password are not defined. Ask your database administrator to set up a Firebird login.
at org.firebirdsql.jdbc.FBDataSource.getConnection(FBDataSource.java:122)
at org.firebirdsql.jdbc.FBDriver.connect(FBDriver.java:131)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:133)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
... 13 more
romarcio
Pelo erro, parece que o problema está no usuario e senha:
Estão corretos? Vc consegue acessar o seu banco pelo gerenciador do firebird com esse login e senha?
natasha
Obrigada
Consigo, eu uso o ibexpert para acessar esse banco com esse login e senha, ele também esta falando da conexão, sera que não poderia ser no endereço do banco?
romarcio
Acho que fala da conexão pq vc não consegue logar.
Eu nunca trabalhei com firebird no java, mas achei essa string de conexão: "jdbc:firebirdsql://localhost:3050/d:\\dirtorio\\banco.FDB"
Tem a porta 3050 e o local onde o banco fica na máquina, tenta assim.