Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.79 KB | None | 0 0
  1. import org.hibernate.SessionFactory;
  2. import org.hibernate.cfg.Configuration;
  3.  
  4. public class HibernateUtil {
  5.  
  6. private static final SessionFactory sessionFactory;
  7.  
  8. static {
  9. try {
  10. // Create the SessionFactory from standard (hibernate.cfg.xml)
  11. // config file.
  12. sessionFactory = new Configuration().configure().buildSessionFactory();
  13. } catch (Throwable ex) {
  14. // Log the exception.
  15. System.err.println("Initial SessionFactory creation failed." + ex);
  16. throw new ExceptionInInitializerError(ex);
  17. }
  18. }
  19.  
  20. public static SessionFactory getSessionFactory() {
  21. return sessionFactory;
  22. }
  23. }
  24.  
  25. <?xml version="1.0" encoding="UTF-8"?>
  26. <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd//hibernate-configuration-3.0.dtd">
  27. <hibernate-configuration>
  28. <session-factory>
  29. <!-- Opciones de Conexión a Base de Datos -->
  30. <property name="hibernate.conecction.driver_class">com.mysql.jdbc.Driver</property>
  31. <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/testws</property>
  32. <property name="hibernate.connection.username">root</property>
  33. <property name="hibernate.connection.password">****</property>
  34. <!-- Dialecto SQL -->
  35. <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  36. <!-- Escribe todas las declaraciones SQL ejecutadas a stdout-->
  37. <property name="show_sql">true</property>
  38. <!-- Nombres de clases entidad-->
  39. <mapping class="com.mycompany.testws.model.Person"/>
  40. </session-factory>
  41. </hibernate-configuration>
  42.  
  43. <?xml version="1.0" encoding="UTF-8"?>
  44. <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">
  45. <modelVersion>4.0.0</modelVersion>
  46.  
  47. <groupId>com.mycompany</groupId>
  48. <artifactId>TestWS</artifactId>
  49. <version>1.0-SNAPSHOT</version>
  50. <packaging>war</packaging>
  51.  
  52. <name>TestWS</name>
  53.  
  54. <properties>
  55. <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
  56. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  57. </properties>
  58.  
  59. <repositories>
  60. <repository>
  61. <id>org.jboss.resteasy</id>
  62. <url>http://repository.jboss.org/maven2/</url>
  63. </repository>
  64. </repositories>
  65.  
  66. <dependencies>
  67. <dependency>
  68. <groupId>javax</groupId>
  69. <artifactId>javaee-web-api</artifactId>
  70. <version>7.0</version>
  71. <scope>provided</scope>
  72. </dependency>
  73. <dependency>
  74. <groupId>org.jboss.resteasy</groupId>
  75. <artifactId>resteasy-jaxrs</artifactId>
  76. <version>2.3.6.Final</version>
  77. </dependency>
  78. <dependency>
  79. <groupId>org.jboss.resteasy</groupId>
  80. <artifactId>resteasy-jaxb-provider</artifactId>
  81. <version>2.3.6.Final</version>
  82. </dependency>
  83. <dependency>
  84. <groupId>org.jboss.resteasy</groupId>
  85. <artifactId>resteasy-jettison-provider</artifactId>
  86. <version>2.3.6.Final</version>
  87. </dependency>
  88.  
  89. <dependency>
  90. <groupId>mysql</groupId>
  91. <artifactId>mysql-connector-java</artifactId>
  92. <version>5.1.34</version>
  93. </dependency>
  94. <dependency>
  95. <groupId>org.hibernate</groupId>
  96. <artifactId>hibernate-core</artifactId>
  97. <version>4.2.2.Final</version>
  98. </dependency>
  99.  
  100. </dependencies>
  101.  
  102. <build>
  103. <plugins>
  104. <plugin>
  105. <groupId>org.apache.maven.plugins</groupId>
  106. <artifactId>maven-compiler-plugin</artifactId>
  107. <version>3.1</version>
  108. <configuration>
  109. <source>1.7</source>
  110. <target>1.7</target>
  111. <compilerArguments>
  112. <endorseddirs>${endorsed.dir}</endorseddirs>
  113. </compilerArguments>
  114. </configuration>
  115. </plugin>
  116. <plugin>
  117. <groupId>org.apache.maven.plugins</groupId>
  118. <artifactId>maven-war-plugin</artifactId>
  119. <version>2.3</version>
  120. <configuration>
  121. <failOnMissingWebXml>false</failOnMissingWebXml>
  122. </configuration>
  123. </plugin>
  124. <plugin>
  125. <groupId>org.apache.maven.plugins</groupId>
  126. <artifactId>maven-dependency-plugin</artifactId>
  127. <version>2.6</version>
  128. <executions>
  129. <execution>
  130. <phase>validate</phase>
  131. <goals>
  132. <goal>copy</goal>
  133. </goals>
  134. <configuration>
  135. <outputDirectory>${endorsed.dir}</outputDirectory>
  136. <silent>true</silent>
  137. <artifactItems>
  138. <artifactItem>
  139. <groupId>javax</groupId>
  140. <artifactId>javaee-endorsed-api</artifactId>
  141. <version>7.0</version>
  142. <type>jar</type>
  143. </artifactItem>
  144. </artifactItems>
  145. </configuration>
  146. </execution>
  147. </executions>
  148. </plugin>
  149. </plugins>
  150. </build>
  151.  
  152. </project>
  153.  
  154. <property name="hibernate.conecction.driver_class">com.mysql.jdbc.Driver</property>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement