Advertisement
Guest User

Untitled

a guest
Jan 11th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. package br.com.crisben.mamute.util;
  2.  
  3. private static SessionFactory fabricaDeSessoes = criarFabricaDeSessoes();
  4.  
  5. public static SessionFactory getFabricaDeSessoes() {
  6. return fabricaDeSessoes;
  7. }
  8.  
  9. private static SessionFactory criarFabricaDeSessoes() {
  10. try {
  11. Configuration configuracao = new Configuration().configure();
  12.  
  13. ServiceRegistry registro = new StandardServiceRegistryBuilder().applySettings(configuracao.getProperties())
  14. .build();
  15.  
  16. SessionFactory fabrica = configuracao.buildSessionFactory(registro);
  17.  
  18. return fabrica;
  19. } catch (Throwable ex) {
  20. System.err.println("A fábrica de sessões não pode ser criada." + ex);
  21. throw new ExceptionInInitializerError(ex);
  22. }
  23. }
  24.  
  25. <?xml version="1.0" encoding="UTF-8"?>
  26.  
  27. <session-factory>
  28.  
  29. <!-- Configurações de Conexão com o Banco de Dados -->
  30. <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
  31. <property name="connection.url">jdbc:mysql://127.0.0.1:3306/mamute</property>
  32. <property name="connection.username">root</property>
  33. <property name="connection.password"></property>
  34.  
  35. <!-- Pool de Conexões -->
  36. <property name="connection.pool_size">1</property>
  37.  
  38. <!-- SQL dialect -->
  39. <property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
  40.  
  41. <!-- Gerenciamento do Contexto das Sessões -->
  42. <property name="current_session_context_class">thread</property>
  43.  
  44. <!-- Cache de Segundo Nível -->
  45. <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
  46.  
  47. <!-- Mostra as SQLs Geradas -->
  48. <property name="show_sql">true</property>
  49.  
  50. <!-- Cria as tabelas do banco de dados -->
  51. <property name="hbm2ddl.auto">create</property>
  52.  
  53. </session-factory>
  54.  
  55. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  56. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  57. <modelVersion>4.0.0</modelVersion>
  58. <groupId>br.com.crisben.mamute</groupId>
  59. <artifactId>Mamute</artifactId>
  60. <version>1.0</version>
  61. <packaging>war</packaging>
  62.  
  63. <!-- Codificação de Caracteres -->
  64. <properties>
  65. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  66. </properties>
  67.  
  68. <!-- Parâmetros de Execução -->
  69. <build>
  70. <!-- Nome do projeto empacotado -->
  71. <finalName>Mamute</finalName>
  72.  
  73. <!-- Plugins -->
  74. <plugins>
  75. <!-- Compilador -->
  76. <plugin>
  77. <groupId>org.apache.maven.plugins</groupId>
  78. <artifactId>maven-compiler-plugin</artifactId>
  79. <version>3.3</version>
  80. <configuration>
  81. <source>1.8</source>
  82. <target>1.8</target>
  83. </configuration>
  84. </plugin>
  85. </plugins>
  86. </build>
  87.  
  88. <!-- Dependências -->
  89. <dependencies>
  90.  
  91. <!-- Hibernate Core -->
  92. <dependency>
  93. <groupId>org.hibernate</groupId>
  94. <artifactId>hibernate-core</artifactId>
  95. <version>5.0.6.Final</version>
  96. </dependency>
  97.  
  98. <!-- JUnit -->
  99. <dependency>
  100. <groupId>junit</groupId>
  101. <artifactId>junit</artifactId>
  102. <version>4.12</version>
  103. </dependency>
  104.  
  105. <!-- MySQL Conector -->
  106. <dependency>
  107. <groupId>mysql</groupId>
  108. <artifactId>mysql-connector-java</artifactId>
  109. <version>5.1.36</version>
  110. </dependency>
  111.  
  112. </dependencies>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement