Warning: Trying to access array offset on value of type bool in /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php on line 16

Warning: Trying to access array offset on value of type bool in /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php on line 16

Warning: Trying to access array offset on value of type bool in /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php on line 16

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758

Warning: Cannot modify header information - headers already sent by (output started at /home/feltexco/public_html/felix/wp-content/plugins/google-maps-ready/modules/options/models/options.php:16) in /home/feltexco/public_html/felix/wp-includes/rest-api/class-wp-rest-server.php on line 1758
{"id":173,"date":"2014-02-28T21:10:17","date_gmt":"2014-03-01T00:10:17","guid":{"rendered":"http:\/\/feltex.com.br\/felix\/?p=173"},"modified":"2014-07-15T11:48:57","modified_gmt":"2014-07-15T14:48:57","slug":"tutorial-de-hibernate","status":"publish","type":"post","link":"https:\/\/www.feltex.com.br\/felix\/tutorial-de-hibernate\/","title":{"rendered":"Tutorial de Hibernate"},"content":{"rendered":"

Objetivo<\/b><\/p>\n

O Hibernate \u00e9 o framework que fornece ferramentas para o mapeamento relacional de objeto (ORM).
\nEste tutorial demonstra o suporte para o framework do Hibernate no IDE Eclipse e como criar os arquivos necess\u00e1rios do Hibernate. Depois de criar objetos Java e configurar a aplica\u00e7\u00e3o usar o Hibernate, voc\u00ea cria uma classe de teste para a inclus\u00e3o e exibi\u00e7\u00e3o dos dados existentes no Banco de Dados.<\/p>\n

<\/p>\n

Configura\u00e7\u00e3o <\/b><\/p>\n

Utilizaremos neste tutorial a vers\u00e3o 4.2.7. Para isso acesse o site oficial do Hibernate: http:\/\/www.hibernate.org\/
\nLink direto: Download<\/a>
\nO arquivo compactado tem v\u00e1rias pastas. A mais importante para n\u00f3s ser\u00e1 a pasta lib\\riquered.
\nUtilizaremos esses arquivos em nossa aplica\u00e7\u00e3o.<\/p>\n

\r\n antlr-2.7.7.jar\r\n dom4j-1.6.1.jar\r\n hibernate-commons-annotations-4.0.2.Final.jar\r\n hibernate-core-4.2.7.Final.jar\r\n hibernate-jpa-2.0-api-1.0.1.Final.jar\r\n javassist-3.18.1-GA.jar\r\n jboss-logging-3.1.0.GA.jar\r\n jboss-transaction-api_1.1_spec-1.0.1.Final.jar\r\n<\/pre>\n

1. Criando Uma aplica\u00e7\u00e3o<\/b><\/p>\n

Abra o seu eclipse. Acesse o menu File >> Project >> Java project<\/p>\n

\"Tutorial-Hibernate-1\"<\/a><\/p>\n

[sb_easy_image num=”1″ column=”1″ order=”random” size=”full” link=”lightbox” ids=”248″ ]<\/p>\n

\"Tutorial-Hibernate-2\"<\/a><\/p>\n

Informe o nome AcademicNet e selecione Finish.<\/p>\n

\"Tutorial-Hibernate-3\"<\/a><\/p>\n

\"Tutorial-Hibernate-4\"<\/a><\/p>\n

Teremos o resultado acima.<\/p>\n

Criaremos uma pasta para adicionar os arquivos do Hibernate. Acesse: File >> New >> Folder<\/p>\n

\"Tutorial-Hibernate-5\"<\/a><\/p>\n

Selecione seu projeto e crie uma Pasta chamada lib.<\/p>\n

\"Tutorial-Hibernate-6\"<\/a><\/p>\n

Descompacte o arquivo que voc\u00ea fez o download do Hibernate.<\/p>\n

\"Tutorial-Hibernate-7\"<\/a><\/p>\n

Em seguida copie os arquivos da subpasta \u201clib\/required\u201d para esta pasta que voc\u00ea acabou de criar no projeto.<\/p>\n

Seu projeto ficar\u00e1 assim:<\/p>\n

\"Tutorial-Hibernate-8\"<\/a><\/p>\n

Agora voc\u00ea deve associar os arquivos ao Build Path<\/b> do projeto.
\nSelecione o seu projeto com o bot\u00e3o direito. Acesse Build Path >> Configure Build Path… Ser\u00e1 exibida a seguinte tela:<\/p>\n

\"Tutorial-Hibernate-9\"<\/a><\/p>\n

Selecione a aba \u201cLibraries\u201d<\/p>\n

\"Tutorial-Hibernate-10\"<\/a><\/p>\n

Clique no bot\u00e3o \u201cAdd JARs…\u201d <\/b> no canto superior direito. Localize a pasta lib e selecione os arquivos JARS. Selecione OK.<\/p>\n

\"Tutorial-Hibernate-11\"<\/a><\/p>\n

\"Tutorial-Hibernate-12\"<\/a><\/p>\n

Selecione o bot\u00e3o \u201cOK\u201d novamente. Agora faremos a codifica\u00e7\u00e3o do projeto.<\/p>\n

2. Criaremos as classes de Entidade <\/b><\/p>\n

Selecione a pasta \u201csrc\u201d com bot\u00e3o direito do mouse. New >> Class<\/p>\n

\"Tutorial-Hibernate-13\"<\/a><\/p>\n

Preencha os campos conforme a imagem abaixo:<\/p>\n

\"Tutorial-Hibernate-14\"<\/a><\/p>\n

Por fim selecione \u201cFinish\u201d.<\/b>
\n Adicione o seguinte c\u00f3digo a sua classe.<\/p>\n

\r\npackage br.com.curso.entidade;\r\n\r\nimport java.io.Serializable;\r\n\r\nimport javax.persistence.Entity;\r\nimport javax.persistence.GeneratedValue;\r\nimport javax.persistence.Id;\r\n\r\n@Entity\r\npublic class Aluno implements Serializable{\r\n\tprivate static final long serialVersionUID = -309513637403441918L;\r\n\r\n\t@Id\r\n\t@GeneratedValue\r\n\tprivate Long matricula;\r\n\t\r\n\tprivate String nome;\r\n\t\r\n\tprivate String telefone;\r\n\r\n\tpublic Long getMatricula() {\r\n\t\treturn matricula;\r\n\t}\r\n\r\n\tpublic void setMatricula(Long matricula) {\r\n\t\tthis.matricula = matricula;\r\n\t}\r\n\r\n\tpublic String getNome() {\r\n\t\treturn nome;\r\n\t}\r\n\r\n\tpublic void setNome(String nome) {\r\n\t\tthis.nome = nome;\r\n\t}\r\n\r\n\tpublic String getTelefone() {\r\n\t\treturn telefone;\r\n\t}\r\n\r\n\tpublic void setTelefone(String telefone) {\r\n\t\tthis.telefone = telefone;\r\n\t}\r\n\r\n\t@Override\r\n\tpublic String toString() {\r\n\t\treturn \"Aluno [matricula=\" + matricula + \", nome=\" + nome\r\n\t\t\t\t+ \", telefone=\" + telefone + \"]\";\r\n\t}\r\n\r\n}\r\n<\/pre>\n

3. Criaremos a Classe HibernateUtil<\/b><\/p>\n

Esta \u00e9 a classe respons\u00e1vel por pegar a conex\u00e3o com o Banco de dados.
\nSelecione a pasta \u201csrc\u201d com bot\u00e3o direito do mouse. New >> Class. Preencha os campos conforme a
\nimagem abaixo:<\/p>\n

\"Tutorial-Hibernate-15\"<\/a><\/p>\n

Insira o c\u00f3digo abaixo na classe.<\/p>\n

\r\npackage br.com.curso.dao;\r\n\r\nimport org.hibernate.Session;\r\nimport org.hibernate.SessionFactory;\r\nimport org.hibernate.cfg.Configuration;\r\nimport org.hibernate.service.ServiceRegistry;\r\nimport org.hibernate.service.ServiceRegistryBuilder;\r\nimport org.hibernate.tool.hbm2ddl.SchemaExport;\r\n\r\npublic class HibernateUtil {\r\n\r\n\tprivate static SessionFactory sessionFactory = null;\r\n\tprivate static ServiceRegistry serviceRegistry;\r\n\r\n\tstatic {\r\n\t\ttry {\r\n\t\t\tsessionFactory = getSessionFactory();\r\n\t\t} catch (Throwable ex) {\r\n\t\t\tSystem.err.println(\"Initial SessionFactory creation failed.\" + ex);\r\n\t\t\tthrow new ExceptionInInitializerError(ex);\r\n\t\t}\r\n\t}\r\n\r\n\tpublic static SessionFactory getSessionFactory() {\r\n\t\tif (sessionFactory == null) {\r\n\t\t\tConfiguration configuration = new Configuration();\r\n\t\t\tconfiguration.configure();\r\n\t\t\tserviceRegistry = new ServiceRegistryBuilder().applySettings(\r\n\t\t\t\t\tconfiguration.getProperties()).buildServiceRegistry();\r\n\t\t\tsessionFactory = configuration.buildSessionFactory(serviceRegistry);\r\n\t\t\tsessionFactory.openSession();\r\n\t\t\treturn sessionFactory;\r\n\t\t}\r\n\t\treturn sessionFactory;\r\n\t}\r\n\r\n\tpublic static Session getSession() {\r\n\t\treturn sessionFactory.openSession();\r\n\t}\r\n\r\n\tpublic static void gerarBanco() {\r\n\t\t\/\/ Carrega as configura\u00e7\u00f5es do arquivo\r\n\t\t\/\/ hibernate.cfg.xml\r\n\t\tConfiguration conf = new Configuration();\r\n\t\tconf.configure();\r\n\t\tSchemaExport se2 = new SchemaExport(conf);\r\n\t\t\/\/ Executa a opera\u00e7\u00e3o da cria\u00e7\u00e3o do Banco de Dados\r\n\t\tse2.create(true, true);\r\n\t}\r\n\r\n}\r\n\r\n<\/pre>\n

4. Criaremos as classes DAO<\/b><\/p>\n

Selecione a pasta \u201csrc\u201d com bot\u00e3o direito do mouse. New >> Class. Preencha os campos conforme a imagem abaixo:<\/p>\n

\"Tutorial-Hibernate-16\"<\/a><\/p>\n

Insira o c\u00f3digo abaixo na classe.<\/p>\n

\r\npackage br.com.curso.dao;\r\n\r\nimport java.util.ArrayList;\r\nimport java.util.List;\r\n\r\nimport org.hibernate.Criteria;\r\nimport org.hibernate.Session;\r\nimport org.hibernate.criterion.Order;\r\nimport org.hibernate.criterion.Restrictions;\r\n\r\nimport br.com.curso.entidade.Aluno;\r\n\r\npublic class AlunoDAO {\r\n\r\n\tprivate Session session;\r\n\r\n\tpublic void incluir(Aluno aluno) {\r\n\t\ttry {\r\n\t\t\tsession = HibernateUtil.getSession();\r\n\t\t\tsession.beginTransaction();\r\n\t\t\tsession.save(aluno);\r\n\t\t\tsession.getTransaction().commit();\r\n\t\t} catch (Exception e) {\r\n\t\t\tsession.getTransaction().rollback();\r\n\t\t\te.printStackTrace();\r\n\t\t} finally {\r\n\t\t\tsession.close();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic void alterar(Aluno aluno) {\r\n\t\ttry {\r\n\t\t\tsession = HibernateUtil.getSession();\r\n\t\t\tsession.beginTransaction();\r\n\t\t\tsession.merge(aluno);\r\n\t\t\tsession.getTransaction().commit();\r\n\t\t} catch (Exception e) {\r\n\t\t\tsession.getTransaction().rollback();\r\n\t\t\te.printStackTrace();\r\n\t\t} finally {\r\n\t\t\tsession.close();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic void excluir(Aluno aluno) {\r\n\t\ttry {\r\n\t\t\tsession = HibernateUtil.getSession();\r\n\t\t\tsession.beginTransaction();\r\n\t\t\tsession.delete(aluno);\r\n\t\t\tsession.getTransaction().commit();\r\n\t\t} catch (Exception e) {\r\n\t\t\tsession.getTransaction().rollback();\r\n\t\t\te.printStackTrace();\r\n\t\t} finally {\r\n\t\t\tsession.close();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic Aluno consultar(int codigo) {\r\n\t\tAluno retorno = new Aluno();\r\n\t\ttry {\r\n\t\t\tsession = HibernateUtil.getSession();\r\n\t\t\tsession.beginTransaction();\r\n\t\t\tretorno = (Aluno) session.get(Aluno.class, codigo);\r\n\t\t\tsession.getTransaction().commit();\r\n\t\t} catch (Exception e) {\r\n\t\t\tsession.getTransaction().rollback();\r\n\t\t\te.printStackTrace();\r\n\t\t} finally {\r\n\t\t\tsession.close();\r\n\t\t}\r\n\t\treturn retorno;\r\n\t}\r\n\r\n\t@SuppressWarnings(\"unchecked\")\r\n\tpublic List listar() {\r\n\t\tList lista = new ArrayList();\r\n\t\ttry {\r\n\t\t\tsession = HibernateUtil.getSession();\r\n\t\t\tsession.beginTransaction();\r\n\t\t\tlista = (List) session.createCriteria(Aluno.class).list();\r\n\t\t\tsession.getTransaction().commit();\r\n\t\t} catch (Exception e) {\r\n\t\t\tsession.getTransaction().rollback();\r\n\t\t\te.printStackTrace();\r\n\t\t} finally {\r\n\t\t\tsession.close();\r\n\t\t}\r\n\t\treturn lista;\r\n\t}\r\n\r\n\t@SuppressWarnings(\"unchecked\")\r\n\tpublic List listar(Aluno aluno) {\r\n\t\tCriteria c = session.createCriteria(Aluno.class);\r\n\t\tif (aluno.getNome().length() > 0) {\r\n\t\t\tc.add(Restrictions.like(\"nome\", aluno.getNome() + \"%\"));\r\n\t\t}\r\n\t\tc.addOrder(Order.asc(\"nome\"));\r\n\t\treturn (List) c.list();\r\n\t}\r\n}\r\n<\/pre>\n


\n5. Criaremos as classes de Teste <\/b><\/p>\n

Selecione a pasta \u201csrc\u201d com bot\u00e3o direito do mouse. New >> Class. Preencha os campos conforme a imagem abaixo:<\/p>\n

\"Tutorial-Hibernate-17\"<\/a><\/p>\n

Por fim selecione \u201cFinish\u201d.<\/b><\/p>\n

Insira o c\u00f3digo abaixo na classe.<\/p>\n

\r\n\r\npackage br.com.curso.teste;\r\n\r\nimport java.util.List;\r\n\r\nimport br.com.curso.dao.AlunoDAO;\r\nimport br.com.curso.entidade.Aluno;\r\n\r\npublic class AlunoTeste {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tnew AlunoTeste().incluirAluno();\r\n\t}\r\n\r\n\t\r\n\r\n\tpublic void incluirAluno() {\r\n\t\tSystem.out.println(this.getClass() + \"Inicio\");\r\n\r\n\t\ttry {\r\n\t\t\t\/\/ Cria a inst\u00e2ncia de um classe de acesso a Dados\r\n\t\t\tAlunoDAO dao = new AlunoDAO();\r\n\t\r\n\r\n\t\t\t\/\/Cria um objeto aluno informando apenas o nome\r\n\t\t\tAluno aluno1 = new Aluno();\r\n\t\t\taluno1.setNome(\"Jose da Silva\");\r\n\t\t\t\r\n\t\t\t\/\/Cria um objeto aluno informando apenas o nome\r\n\t\t\tAluno aluno2 = new Aluno();\r\n\t\t\taluno2.setNome(\"Maria da Silva\");\r\n\t\t\t\r\n\t\t\t\/\/Realiza a inclus\u00e3o de um aluno\r\n\t\t\tdao.incluir(aluno1);\r\n\t\t\t\r\n\t\t\t\/\/Realiza a inclus\u00e3o de um aluno\r\n\t\t\tdao.incluir(aluno2);\r\n\t\t\t\r\n\t\t\t\r\n\t\t\t\/\/ Consulta a lista de usu\u00e1rios cadastrados no Banco\r\n\t\t\tList listaAluno = dao.listar();\r\n\t\t\t\r\n\t\t\t\r\n\t\t\t\r\n\t\t\t\/\/ Realiza um loop para exibir todos os registro existentes no Banco de dados\r\n\t\t\tSystem.out.println(\"==================  Alunos Cadastrados ============================\");\r\n\t\t\tfor (Aluno a : listaAluno) {\r\n\t\t\t\tSystem.out.println(a);\r\n\t\t\t}\r\n\r\n\t\t} catch (Exception e) {\r\n\t\t\te.printStackTrace();\r\n\t\t}\r\n\t\tSystem.out.println(this.getClass() + \"Fim\");\r\n\t}\r\n}\r\n<\/pre>\n

6. Criaremos o arquivo de configura\u00e7\u00e3o do Hibernate<\/b><\/p>\n

Selecione a pasta \u201csrc\u201d com bot\u00e3o direito do mouse. New >> Other.. >> XML >> XML File. Preencha os campos conforme a imagem abaixo:<\/p>\n

\"Tutorial-Hibernate-18\"<\/a><\/p>\n

\"Tutorial-Hibernate-19\"<\/a><\/p>\n

Por fim selecione \u201cFinish\u201d.<\/b><\/p>\n

Insira o c\u00f3digo abaixo no arquivo \u201chibernate.cfg.xml\u201d. Nesse arquivos temos as seguintes dados:<\/p>\n

\r\n\r\n\r\n\r\n\r\n\t\r\n\t\t\r\n\t\torg.postgresql.Driver<\/property>\r\n\t\tjdbc:postgresql:\/\/localhost:5432\/BDAcademicNet<\/property>\r\n\t\tpostgres<\/property>\r\n\t\tteco01<\/property>\r\n\t\t\r\n\t\t\r\n\t\t\r\n\t\torg.hibernate.dialect.PostgreSQLDialect<\/property>\r\n\t\ttrue<\/property>\r\n\t\ttrue<\/property>\r\n\t\t20<\/property>\r\n\r\n\t\tupdate<\/property>\r\n\t\t\t\t\r\n\t\t\r\n\t\t\t\t\r\n\t\t\t\t\t\t\r\n\t<\/session-factory>\r\n<\/hibernate-configuration>\r\n<\/pre>\n

Conex\u00e3o com o banco de dados:<\/p>\n

7. Adicionar o Driver de Banco de Dados<\/b><\/p>\n

Neste nosso exemplo utilizaremos o Banco PostgreSQL. Para isso devemos ter o Driver espec\u00edfico de cada banco de dados.
\nO Site oficial do PostgreSQL \u00e9 esse http:\/\/jdbc.postgresql.org\/download.html. Acesse e conhe\u00e7a um pouco mais sobre este banco. Fa\u00e7a o Download o Manual do usu\u00e1rio para consultar quando tiver d\u00favidas.<\/p>\n

Link Direto para baixar o driver de banco de dados: http:\/\/jdbc.postgresql.org\/download\/postgresql-
\n9.3-1100.jdbc4.jar
\nSalve o arquivo diretamente na pasta lib<\/b> criada em nosso projeto.
\nEm seguida \u00e9 necess\u00e1rio fazer o apontamento do arquivo no projeto.<\/p>\n

Selecione o seu projeto com o bot\u00e3o direito. Acesse Build Path >> Configure Build Path… Ser\u00e1 exibida a seguinte tela:<\/p>\n

\"Tutorial-Hibernate-21\"<\/a><\/p>\n

Selecione a Aba \u201cLibraries\u201d<\/p>\n

\"Tutorial-Hibernate-22\"<\/a><\/p>\n

\"Tutorial-Hibernate-23\"<\/a><\/p>\n

Clique em OK.<\/p>\n

8. Criaremos o Banco de Dados<\/b><\/p>\n

\u00c9 necess\u00e1rio criar o banco de dados para que o Hibernate consiga criar as estruturas de tabelas. Abra o pgAdminIII.<\/p>\n

Selecione o servidor com um duplo clique. Selecione o n\u00f3 Database com o bot\u00e3o direito >> \u201cNew Data Base\u201d.
\nDigite o nome do nosso banco de dados “BDAcademicNet”<\/p>\n

\"Tutorial-Hibernate-24\"<\/a><\/p>\n

\"Tutorial-Hibernate-25\"<\/a><\/p>\n

Selecione \u201cOK\u201d<\/b><\/p>\n

Seu banco estar\u00e1 criado.<\/p>\n

\"Tutorial-Hibernate-26\"<\/a><\/p>\n

V\u00e1 ao Eclipse selecione a sua classe AlunoTeste com o bot\u00e3o direito<\/p>\n

Selecione \u201cRun As\u201d \u0001 >> Java Application.<\/p>\n

Na console dever\u00e1 aparecer um resultado parecido com esse na console.<\/p>\n

\r\n\r\nHibernate:\r\nselect\r\nnextval ('hibernate_sequence')\r\nHibernate:\r\ninsert\r\ninto\r\nAluno\r\n(nome, telefone, matricula)\r\nvalues (?, ?, ?)\r\nHibernate:\r\nselect\r\nnextval ('hibernate_sequence')\r\nHibernate:\r\ninsert\r\ninto\r\nAluno\r\n(nome, telefone, matricula)\r\nvalues\r\n(?, ?, ?)\r\nHibernate:\r\nselect\r\nthis_.matricula as matricul1_0_0_,\r\nthis_.nome as nome2_0_0_,\r\nthis_.telefone as telefone3_0_0_\r\nfrom\r\nAluno this_\r\n================== Alunos Cadastrados ============================\r\nAluno [matricula=1, nome=Jose da Silva, telefone=null]\r\nAluno [matricula=2, nome=Maria da Silva, telefone=null]\r\nclass br.com.curso.teste.AlunoTesteFim\r\n\r\n<\/pre>\n

9. Veremos o resultado no Banco de Dados<\/b><\/p>\n

Selecione o seu banco de dados no pgAdmin III. E clique no bot\u00e3o (exibido na barra de menu superior) com uma lupa escrita \u201cSQL\u201d<\/b>.<\/p>\n

\"Tutorial-Hibernate-27\"<\/a><\/p>\n

Na tela exibida escreva o seguinte comando: Select * from aluno;
\nDever\u00e1 aparecer o resultado conforme a imagem abaixo:<\/p>\n

Pronto! Se voc\u00ea seguiu o passo-a-passo. Estar\u00e1 tudo funcionando!
\n Vida que segue!<\/b><\/p>\n

Se houve problemas na sua execu\u00e7\u00e3o, ent\u00e3o vamos analisar os mais comuns e suas solu\u00e7\u00f5es.
\n10. Erros Poss\u00edveis<\/b><\/p>\n


\nInitial SessionFactory creation
\nfailed.org.hibernate.service.classloading.spi.ClassLoadingExcep
\ntion: Specified JDBC Driver org.postgresql.Driver could not be
\nloaded
\njava.lang.NullPointerException
\nat br.com.curso.dao.AlunoDAO.incluir(AlunoDAO.java:27)
\nat
\nbr.com.curso.teste.AlunoTeste.incluirAluno(AlunoTeste.java:26)
\nat br.com.curso.teste.AlunoTeste.main(AlunoTeste.java:9)<\/p>\n

Motivo: <\/p>\n

O Driver do Banco de dados n\u00e3o foi
\nadicionado. Veja o passo \u201cAdicionar o
\nDriver de Banco de Dados\u201d
\n<\/code><\/p>\n


\n\"ERROR: HHH000299: Could not complete schema update
\norg.postgresql.util.PSQLException: FATAL: banco de dados
\n\"BDAcademicNet\" n?o existe\"<\/p>\n

Motivo:
\n Voc\u00ea n\u00e3o criou o banco de Dados no PostgreSQL
\n<\/code><\/p>\n


\n ERROR: HHH000299: Could not complete schema update
\n org.postgresql.util.PSQLException: FATAL: autentica\u00e7\u00e3o do tipo
\n password falhou para usu?rio \"postgres\"<\/p>\n

Motivo:
\nVerifique se o usu\u00e1rio e senha no arquivo \u201chibernate.cfg.xml\u201d conferem
\ncom a identifica\u00e7\u00e3o do seu banco de dados.
\nPropriedades:
\n hibernate.connection.username
\n hibernate.connection.password
\n<\/code><\/p>\n


\norg.postgresql.util.PSQLException: A tentativa de conex\u00e3o
\nfalhou.<\/p>\n

Motivo:
\nVeja no arquivo \u201chibernate.cfg.xml\u201d se a propriedade hibernate.connection.url est\u00e1 com as configura\u00e7\u00f5es de acesso ao seu
\nbanco de dados corretamente. Deve ser: jdbc:postgresql:\/\/localhost:5432\/BDAcademicNet
\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"

Objetivo O Hibernate \u00e9 o framework que fornece ferramentas para o mapeamento relacional de objeto (ORM). Este tutorial demonstra o suporte para o framework do Hibernate no IDE Eclipse e como criar os arquivos necess\u00e1rios do Hibernate. Depois de criar …<\/p>\n

Tutorial de Hibernate<\/span> Read More »<\/a><\/p>\n

<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0},"categories":[21,1],"tags":[29],"yoast_head":"\nTutorial de Hibernate<\/title>\n<meta name=\"description\" content=\"Tutorial de Hibernate\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.feltex.com.br\/felix\/tutorial-de-hibernate\/\" \/>\n<meta property=\"og:locale\" content=\"pt_BR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Tutorial de Hibernate\" \/>\n<meta property=\"og:description\" content=\"Tutorial de Hibernate\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.feltex.com.br\/felix\/tutorial-de-hibernate\/\" \/>\n<meta property=\"og:site_name\" content=\"Aprenda Java\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/feltex.br\" \/>\n<meta property=\"article:published_time\" content=\"2014-03-01T00:10:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-07-15T14:48:57+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.feltex.com.br\/felix\/wp-content\/uploads\/2014\/02\/Tutorial-Hibernate-1-300x208.png\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"Andr\u00e9 F\u00e9lix\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. tempo de leitura\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.feltex.com.br\/felix\/#website\",\"url\":\"https:\/\/www.feltex.com.br\/felix\/\",\"name\":\"Aprenda Java\",\"description\":\"Cursos de java, SQL e Engenharia de Software\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.feltex.com.br\/felix\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"pt-BR\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.feltex.com.br\/felix\/tutorial-de-hibernate\/#primaryimage\",\"inLanguage\":\"pt-BR\",\"url\":\"http:\/\/www.feltex.com.br\/felix\/wp-content\/uploads\/2014\/02\/Tutorial-Hibernate-1-300x208.png\",\"contentUrl\":\"http:\/\/www.feltex.com.br\/felix\/wp-content\/uploads\/2014\/02\/Tutorial-Hibernate-1-300x208.png\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.feltex.com.br\/felix\/tutorial-de-hibernate\/#webpage\",\"url\":\"https:\/\/www.feltex.com.br\/felix\/tutorial-de-hibernate\/\",\"name\":\"Tutorial de Hibernate\",\"isPartOf\":{\"@id\":\"https:\/\/www.feltex.com.br\/felix\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.feltex.com.br\/felix\/tutorial-de-hibernate\/#primaryimage\"},\"datePublished\":\"2014-03-01T00:10:17+00:00\",\"dateModified\":\"2014-07-15T14:48:57+00:00\",\"author\":{\"@id\":\"https:\/\/www.feltex.com.br\/felix\/#\/schema\/person\/1e49f842c6254b4561b66ccf573c2069\"},\"description\":\"Tutorial de Hibernate\",\"breadcrumb\":{\"@id\":\"https:\/\/www.feltex.com.br\/felix\/tutorial-de-hibernate\/#breadcrumb\"},\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.feltex.com.br\/felix\/tutorial-de-hibernate\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.feltex.com.br\/felix\/tutorial-de-hibernate\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Tutorial de Hibernate\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.feltex.com.br\/felix\/#\/schema\/person\/1e49f842c6254b4561b66ccf573c2069\",\"name\":\"Andr\\u00e9 F\\u00e9lix\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.feltex.com.br\/felix\/#personlogo\",\"inLanguage\":\"pt-BR\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d2d9cc82cab40245e6f803982b1448e6?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d2d9cc82cab40245e6f803982b1448e6?s=96&r=g\",\"caption\":\"Andr\\u00e9 F\\u00e9lix\"},\"sameAs\":[\"http:\/\/www.feltex.com.br\"],\"url\":\"https:\/\/www.feltex.com.br\/felix\/author\/andre.felix\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Tutorial de Hibernate","description":"Tutorial de Hibernate","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.feltex.com.br\/felix\/tutorial-de-hibernate\/","og_locale":"pt_BR","og_type":"article","og_title":"Tutorial de Hibernate","og_description":"Tutorial de Hibernate","og_url":"https:\/\/www.feltex.com.br\/felix\/tutorial-de-hibernate\/","og_site_name":"Aprenda Java","article_publisher":"https:\/\/www.facebook.com\/feltex.br","article_published_time":"2014-03-01T00:10:17+00:00","article_modified_time":"2014-07-15T14:48:57+00:00","og_image":[{"url":"http:\/\/www.feltex.com.br\/felix\/wp-content\/uploads\/2014\/02\/Tutorial-Hibernate-1-300x208.png"}],"twitter_misc":{"Escrito por":"Andr\u00e9 F\u00e9lix","Est. tempo de leitura":"9 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/www.feltex.com.br\/felix\/#website","url":"https:\/\/www.feltex.com.br\/felix\/","name":"Aprenda Java","description":"Cursos de java, SQL e Engenharia de Software","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.feltex.com.br\/felix\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"pt-BR"},{"@type":"ImageObject","@id":"https:\/\/www.feltex.com.br\/felix\/tutorial-de-hibernate\/#primaryimage","inLanguage":"pt-BR","url":"http:\/\/www.feltex.com.br\/felix\/wp-content\/uploads\/2014\/02\/Tutorial-Hibernate-1-300x208.png","contentUrl":"http:\/\/www.feltex.com.br\/felix\/wp-content\/uploads\/2014\/02\/Tutorial-Hibernate-1-300x208.png"},{"@type":"WebPage","@id":"https:\/\/www.feltex.com.br\/felix\/tutorial-de-hibernate\/#webpage","url":"https:\/\/www.feltex.com.br\/felix\/tutorial-de-hibernate\/","name":"Tutorial de Hibernate","isPartOf":{"@id":"https:\/\/www.feltex.com.br\/felix\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.feltex.com.br\/felix\/tutorial-de-hibernate\/#primaryimage"},"datePublished":"2014-03-01T00:10:17+00:00","dateModified":"2014-07-15T14:48:57+00:00","author":{"@id":"https:\/\/www.feltex.com.br\/felix\/#\/schema\/person\/1e49f842c6254b4561b66ccf573c2069"},"description":"Tutorial de Hibernate","breadcrumb":{"@id":"https:\/\/www.feltex.com.br\/felix\/tutorial-de-hibernate\/#breadcrumb"},"inLanguage":"pt-BR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.feltex.com.br\/felix\/tutorial-de-hibernate\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.feltex.com.br\/felix\/tutorial-de-hibernate\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Tutorial de Hibernate"}]},{"@type":"Person","@id":"https:\/\/www.feltex.com.br\/felix\/#\/schema\/person\/1e49f842c6254b4561b66ccf573c2069","name":"Andr\u00e9 F\u00e9lix","image":{"@type":"ImageObject","@id":"https:\/\/www.feltex.com.br\/felix\/#personlogo","inLanguage":"pt-BR","url":"https:\/\/secure.gravatar.com\/avatar\/d2d9cc82cab40245e6f803982b1448e6?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d2d9cc82cab40245e6f803982b1448e6?s=96&r=g","caption":"Andr\u00e9 F\u00e9lix"},"sameAs":["http:\/\/www.feltex.com.br"],"url":"https:\/\/www.feltex.com.br\/felix\/author\/andre.felix\/"}]}},"_links":{"self":[{"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/posts\/173"}],"collection":[{"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/comments?post=173"}],"version-history":[{"count":48,"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/posts\/173\/revisions"}],"predecessor-version":[{"id":995,"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/posts\/173\/revisions\/995"}],"wp:attachment":[{"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/media?parent=173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/categories?post=173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.feltex.com.br\/felix\/wp-json\/wp\/v2\/tags?post=173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}

\"Tutorial-Hibernate-20\"<\/a><\/p>\n