Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.hibernate.SessionFactory;
- import org.hibernate.cfg.Configuration;
- public class HibernateUtil {
- private static final SessionFactory sessionFactory;
- static {
- try {
- // Create the SessionFactory from standard (hibernate.cfg.xml)
- // config file.
- sessionFactory = new Configuration().configure().buildSessionFactory();
- } catch (Throwable ex) {
- // Log the exception.
- System.err.println("Initial SessionFactory creation failed." + ex);
- throw new ExceptionInInitializerError(ex);
- }
- }
- public static SessionFactory getSessionFactory() {
- return sessionFactory;
- }
- }
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd//hibernate-configuration-3.0.dtd">
- <hibernate-configuration>
- <session-factory>
- <!-- Opciones de Conexión a Base de Datos -->
- <property name="hibernate.conecction.driver_class">com.mysql.jdbc.Driver</property>
- <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/testws</property>
- <property name="hibernate.connection.username">root</property>
- <property name="hibernate.connection.password">****</property>
- <!-- Dialecto SQL -->
- <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
- <!-- Escribe todas las declaraciones SQL ejecutadas a stdout-->
- <property name="show_sql">true</property>
- <!-- Nombres de clases entidad-->
- <mapping class="com.mycompany.testws.model.Person"/>
- </session-factory>
- </hibernate-configuration>
- <?xml version="1.0" encoding="UTF-8"?>
- <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>com.mycompany</groupId>
- <artifactId>TestWS</artifactId>
- <version>1.0-SNAPSHOT</version>
- <packaging>war</packaging>
- <name>TestWS</name>
- <properties>
- <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- </properties>
- <repositories>
- <repository>
- <id>org.jboss.resteasy</id>
- <url>http://repository.jboss.org/maven2/</url>
- </repository>
- </repositories>
- <dependencies>
- <dependency>
- <groupId>javax</groupId>
- <artifactId>javaee-web-api</artifactId>
- <version>7.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.resteasy</groupId>
- <artifactId>resteasy-jaxrs</artifactId>
- <version>2.3.6.Final</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.resteasy</groupId>
- <artifactId>resteasy-jaxb-provider</artifactId>
- <version>2.3.6.Final</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.resteasy</groupId>
- <artifactId>resteasy-jettison-provider</artifactId>
- <version>2.3.6.Final</version>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>5.1.34</version>
- </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-core</artifactId>
- <version>4.2.2.Final</version>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>3.1</version>
- <configuration>
- <source>1.7</source>
- <target>1.7</target>
- <compilerArguments>
- <endorseddirs>${endorsed.dir}</endorseddirs>
- </compilerArguments>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-war-plugin</artifactId>
- <version>2.3</version>
- <configuration>
- <failOnMissingWebXml>false</failOnMissingWebXml>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <version>2.6</version>
- <executions>
- <execution>
- <phase>validate</phase>
- <goals>
- <goal>copy</goal>
- </goals>
- <configuration>
- <outputDirectory>${endorsed.dir}</outputDirectory>
- <silent>true</silent>
- <artifactItems>
- <artifactItem>
- <groupId>javax</groupId>
- <artifactId>javaee-endorsed-api</artifactId>
- <version>7.0</version>
- <type>jar</type>
- </artifactItem>
- </artifactItems>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </project>
- <property name="hibernate.conecction.driver_class">com.mysql.jdbc.Driver</property>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement