Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package br.com.crisben.mamute.util;
- private static SessionFactory fabricaDeSessoes = criarFabricaDeSessoes();
- public static SessionFactory getFabricaDeSessoes() {
- return fabricaDeSessoes;
- }
- private static SessionFactory criarFabricaDeSessoes() {
- try {
- Configuration configuracao = new Configuration().configure();
- ServiceRegistry registro = new StandardServiceRegistryBuilder().applySettings(configuracao.getProperties())
- .build();
- SessionFactory fabrica = configuracao.buildSessionFactory(registro);
- return fabrica;
- } catch (Throwable ex) {
- System.err.println("A fábrica de sessões não pode ser criada." + ex);
- throw new ExceptionInInitializerError(ex);
- }
- }
- <?xml version="1.0" encoding="UTF-8"?>
- <session-factory>
- <!-- Configurações de Conexão com o Banco de Dados -->
- <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
- <property name="connection.url">jdbc:mysql://127.0.0.1:3306/mamute</property>
- <property name="connection.username">root</property>
- <property name="connection.password"></property>
- <!-- Pool de Conexões -->
- <property name="connection.pool_size">1</property>
- <!-- SQL dialect -->
- <property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
- <!-- Gerenciamento do Contexto das Sessões -->
- <property name="current_session_context_class">thread</property>
- <!-- Cache de Segundo Nível -->
- <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
- <!-- Mostra as SQLs Geradas -->
- <property name="show_sql">true</property>
- <!-- Cria as tabelas do banco de dados -->
- <property name="hbm2ddl.auto">create</property>
- </session-factory>
- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>br.com.crisben.mamute</groupId>
- <artifactId>Mamute</artifactId>
- <version>1.0</version>
- <packaging>war</packaging>
- <!-- Codificação de Caracteres -->
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- </properties>
- <!-- Parâmetros de Execução -->
- <build>
- <!-- Nome do projeto empacotado -->
- <finalName>Mamute</finalName>
- <!-- Plugins -->
- <plugins>
- <!-- Compilador -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>3.3</version>
- <configuration>
- <source>1.8</source>
- <target>1.8</target>
- </configuration>
- </plugin>
- </plugins>
- </build>
- <!-- Dependências -->
- <dependencies>
- <!-- Hibernate Core -->
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-core</artifactId>
- <version>5.0.6.Final</version>
- </dependency>
- <!-- JUnit -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.12</version>
- </dependency>
- <!-- MySQL Conector -->
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>5.1.36</version>
- </dependency>
- </dependencies>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement