alguém pode me ajudar? não achei nenhum tutorial na internet.
Feijão com arroz hibernate com hsql
1º Passo: Adicionando as dependências no pom.xml
<dependencies>
<!-- hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.10.Final</version>
</dependency>
<!-- hsql -->
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.3.2</version>
<scope>runtime</scope>
</dependency>
</dependencies>
2º Passo: Adicionando o arquivo persistence.xml
Observação importante, a pasta onde o arquivo deve ser colcado é ../src/main/resources/META-INF/
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="projeto">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />
<property name="javax.persistence.jdbc.url"
value="jdbc:hsqldb:file:db/projeto;locked=false;shutdown=true" />
<property name="javax.persistence.jdbc.user" value="sa" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
</properties>
</persistence-unit>
</persistence>
3º Passo: Criando uma fábrica de conexões
classe EntityFactory
public class EntityFactory {
private static EntityManagerFactory emf = Persistence.createEntityManagerFactory("projeto");
public static EntityManager getEntityManager(){
return emf.createEntityManager();
}
}
O próximo passo é criar as classes de entidades e seus respectivos Dao’s. Abraço.
não tem uma vídeo aula n? pq depois que fiz esse procedimento aí não não funciona mais nada.
Amigo deve ter, tente buscar no google, a configuração acima é pra ser utilizado com o banco de dados HSQLDB, achei que você estava começando um projeto do zero, se você já tem um projeto vinculado há algum banco de dados, e apenas quer adicionar o hibernate, você precisa informar detalhes do projeto.
já olhei todos os tutoriais possíveis e mesmo assim meu projeto não funciona.
apareceu um erro em um dos pacotes, porém não sei onde resolver.segue o print.
Coloca o stacktrace do erro por favor.
set 04, 2017 10:36:09 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
ADVERTÊNCIA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property ‘source’ to ‘org.eclipse.jst.jee.server:ProjetoFinal’ did not find a matching property.
set 04, 2017 10:36:09 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
ADVERTÊNCIA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property ‘source’ to ‘org.eclipse.jst.jee.server:SISTEMA_ESCOLAR’ did not find a matching property.
set 04, 2017 10:36:09 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
ADVERTÊNCIA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property ‘source’ to ‘org.eclipse.jst.jee.server:BIBLIOTECA_TOPICOS’ did not find a matching property.
set 04, 2017 10:36:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Server version: Apache Tomcat/7.0.77
set 04, 2017 10:36:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Server built: Mar 28 2017 16:01:48 UTC
set 04, 2017 10:36:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Server number: 7.0.77.0
set 04, 2017 10:36:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: OS Name: Windows 7
set 04, 2017 10:36:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: OS Version: 6.1
set 04, 2017 10:36:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Architecture: x86
set 04, 2017 10:36:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Java Home: C:\FTC_DEV\jdk8\jre
set 04, 2017 10:36:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: JVM Version: 1.8.0_73-b02
set 04, 2017 10:36:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: JVM Vendor: Oracle Corporation
set 04, 2017 10:36:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: CATALINA_BASE: C:\FTC_DEV\workspace\tpi.metadata.plugins\org.eclipse.wst.server.core\tmp2
set 04, 2017 10:36:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: CATALINA_HOME: C:\apache-tomcat-7.0.77
set 04, 2017 10:36:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Dcatalina.base=C:\FTC_DEV\workspace\tpi.metadata.plugins\org.eclipse.wst.server.core\tmp2
set 04, 2017 10:36:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Dcatalina.home=C:\apache-tomcat-7.0.77
set 04, 2017 10:36:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Dwtp.deploy=C:\FTC_DEV\workspace\tpi.metadata.plugins\org.eclipse.wst.server.core\tmp2\wtpwebapps
set 04, 2017 10:36:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Djava.endorsed.dirs=C:\apache-tomcat-7.0.77\endorsed
set 04, 2017 10:36:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Dfile.encoding=Cp1252
set 04, 2017 10:36:09 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFORMAÇÕES: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\FTC_DEV\jdk8\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/FTC_DEV/jdk8/jre/bin/client;C:/FTC_DEV/jdk8/jre/bin;C:/FTC_DEV/jdk8/jre/lib/i386;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files\Microsoft SQL Server\120\Tools\Binn;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn;C:\Program Files\Microsoft SQL Server\120\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn;C:\Program Files\Intel\WiFi\bin;C:\Program Files\Common Files\Intel\WirelessCommon;C:\Program Files (x86)\Skype\Phone;C:\Program Files\Java\jre1.8.0_131\bin;C:\Program Files\OpenVPN\bin;;C:\FTC_DEV\eclipse;;.
set 04, 2017 10:36:09 PM org.apache.coyote.AbstractProtocol init
INFORMAÇÕES: Initializing ProtocolHandler [“http-bio-8080”]
set 04, 2017 10:36:09 PM org.apache.coyote.AbstractProtocol init
INFORMAÇÕES: Initializing ProtocolHandler [“ajp-bio-8009”]
set 04, 2017 10:36:09 PM org.apache.catalina.startup.Catalina load
INFORMAÇÕES: Initialization processed in 687 ms
set 04, 2017 10:36:09 PM org.apache.catalina.core.StandardService startInternal
INFORMAÇÕES: Starting service Catalina
set 04, 2017 10:36:09 PM org.apache.catalina.core.StandardEngine startInternal
INFORMAÇÕES: Starting Servlet Engine: Apache Tomcat/7.0.77
set 04, 2017 10:36:10 PM org.apache.catalina.startup.TldConfig execute
INFORMAÇÕES: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
set 04, 2017 10:36:10 PM org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
INFORMAÇÕES: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [230] milliseconds.
set 04, 2017 10:36:10 PM org.apache.catalina.startup.TldConfig execute
INFORMAÇÕES: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
set 04, 2017 10:36:11 PM org.apache.catalina.startup.TaglibUriRule body
INFORMAÇÕES: TLD skipped. URI: http://java.sun.com/jstl/core_rt is already defined
set 04, 2017 10:36:11 PM org.apache.catalina.startup.TaglibUriRule body
INFORMAÇÕES: TLD skipped. URI: http://java.sun.com/jstl/core is already defined
set 04, 2017 10:36:11 PM org.apache.catalina.startup.TaglibUriRule body
INFORMAÇÕES: TLD skipped. URI: http://java.sun.com/jsp/jstl/core is already defined
set 04, 2017 10:36:11 PM org.apache.catalina.startup.TaglibUriRule body
INFORMAÇÕES: TLD skipped. URI: http://java.sun.com/jstl/fmt_rt is already defined
set 04, 2017 10:36:11 PM org.apache.catalina.startup.TaglibUriRule body
INFORMAÇÕES: TLD skipped. URI: http://java.sun.com/jstl/fmt is already defined
set 04, 2017 10:36:11 PM org.apache.catalina.startup.TaglibUriRule body
INFORMAÇÕES: TLD skipped. URI: http://java.sun.com/jsp/jstl/fmt is already defined
set 04, 2017 10:36:11 PM org.apache.catalina.startup.TaglibUriRule body
INFORMAÇÕES: TLD skipped. URI: http://java.sun.com/jsp/jstl/functions is already defined
set 04, 2017 10:36:11 PM org.apache.catalina.startup.TaglibUriRule body
INFORMAÇÕES: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/permittedTaglibs is already defined
set 04, 2017 10:36:11 PM org.apache.catalina.startup.TaglibUriRule body
INFORMAÇÕES: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/scriptfree is already defined
set 04, 2017 10:36:11 PM org.apache.catalina.startup.TaglibUriRule body
INFORMAÇÕES: TLD skipped. URI: http://java.sun.com/jstl/sql_rt is already defined
set 04, 2017 10:36:11 PM org.apache.catalina.startup.TaglibUriRule body
INFORMAÇÕES: TLD skipped. URI: http://java.sun.com/jstl/sql is already defined
set 04, 2017 10:36:11 PM org.apache.catalina.startup.TaglibUriRule body
INFORMAÇÕES: TLD skipped. URI: http://java.sun.com/jsp/jstl/sql is already defined
set 04, 2017 10:36:11 PM org.apache.catalina.startup.TaglibUriRule body
INFORMAÇÕES: TLD skipped. URI: http://java.sun.com/jstl/xml_rt is already defined
set 04, 2017 10:36:11 PM org.apache.catalina.startup.TaglibUriRule body
INFORMAÇÕES: TLD skipped. URI: http://java.sun.com/jstl/xml is already defined
set 04, 2017 10:36:11 PM org.apache.catalina.startup.TaglibUriRule body
INFORMAÇÕES: TLD skipped. URI: http://java.sun.com/jsp/jstl/xml is already defined
set 04, 2017 10:36:11 PM org.apache.catalina.startup.TldConfig execute
INFORMAÇÕES: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
set 04, 2017 10:36:12 PM org.apache.catalina.startup.TldConfig execute
INFORMAÇÕES: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
set 04, 2017 10:36:12 PM org.apache.coyote.AbstractProtocol start
INFORMAÇÕES: Starting ProtocolHandler [“http-bio-8080”]
set 04, 2017 10:36:12 PM org.apache.coyote.AbstractProtocol start
INFORMAÇÕES: Starting ProtocolHandler [“ajp-bio-8009”]
set 04, 2017 10:36:12 PM org.apache.catalina.startup.Catalina start
INFORMAÇÕES: Server startup in 2212 ms