Created
February 4, 2014 17:43
-
-
Save andreluizf/8808607 to your computer and use it in GitHub Desktop.
projeto hibernate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> | |
<!-- Database connection settings --> | |
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> | |
<property name="hibernate.connection.url">jdbc:mysql://ativacao.xkeysti.com.br:3306/DB_CAX</property> | |
<property name="hibernate.connection.username">xkey</property> | |
<property name="hibernate.connection.password">b50988995b</property> | |
<!-- JDBC connection pool (use the built-in) --> | |
<property name="hibernate.connection.pool_size">100</property> | |
<!-- SQL dialect --> | |
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> | |
<!-- Enable Hibernate's automatic session context management | |
<property name="hibernate.current_session_context_class">org.hibernate.context.internal.JTASessionContext</property>--> | |
<property name="hibernate.current_session_context_class">org.hibernate.context.internal.JTASessionContext</property> | |
<!-- Disable the second-level cache --> | |
<property name="hibernate.cache.provider_class">org.hibernate.cache.internal.NoCacheProvider | |
</property> | |
<!-- Echo all executed SQL to stdout --> | |
<property name="hibernate.show_sql">true</property> | |
<!-- Drop and re-create the database schema on startup --> | |
<property name="hibernate.default_batch_fetch_size">15</property> | |
<property name="hibernate.transaction.auto_close_session">true</property> | |
<mapping class="br.com.testJunithibernate.projeto.model.Produto"/> | |
</session-factory> | |
</hibernate-configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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.testJunithibernate</groupId> | |
<artifactId>projeto</artifactId> | |
<version>0.0.1-SNAPSHOT</version> | |
<packaging>jar</packaging> | |
<name>projeto</name> | |
<url>http://maven.apache.org</url> | |
<properties> | |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
</properties> | |
<dependencies> | |
<dependency> | |
<groupId>junit</groupId> | |
<artifactId>junit</artifactId> | |
<version>4.8.1</version> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.hibernate</groupId> | |
<artifactId>hibernate-entitymanager</artifactId> | |
<version>4.1.7.Final</version> | |
</dependency> | |
<dependency> | |
<groupId>org.hibernate</groupId> | |
<artifactId>hibernate-core</artifactId> | |
<version>4.1.7.Final</version> | |
</dependency> | |
<dependency> | |
<groupId>org.hibernate</groupId> | |
<artifactId>hibernate-validator</artifactId> | |
<version>4.3.0.Final</version> | |
</dependency> | |
<dependency> | |
<groupId>javax.transaction</groupId> | |
<artifactId>jta</artifactId> | |
<version>1.1</version> | |
</dependency> | |
<dependency> | |
<groupId>org.hibernate</groupId> | |
<artifactId>hibernate-c3p0</artifactId> | |
<version>4.1.7.Final</version> | |
</dependency> | |
<dependency> | |
<groupId>mysql</groupId> | |
<artifactId>mysql-connector-java</artifactId> | |
<version>5.1.28</version> | |
</dependency> | |
</dependencies> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.testJunithibernate.projeto.model; | |
import java.io.Serializable; | |
import java.math.BigDecimal; | |
import javax.persistence.Basic; | |
import javax.persistence.Column; | |
import javax.persistence.Entity; | |
import javax.persistence.GeneratedValue; | |
import javax.persistence.GenerationType; | |
import javax.persistence.Id; | |
import javax.persistence.Table; | |
@Entity | |
@Table(name="PRODUTO") | |
public class Produto implements Serializable{ | |
@Id | |
@GeneratedValue(strategy=GenerationType.IDENTITY) | |
@Basic(optional=false) | |
@Column(name="COD_PRODUTO") | |
private Integer id; | |
@Column(name="DESCRICAO") | |
private String descricao; | |
@Column(name="VALOR") | |
private BigDecimal valor; | |
@Column(name="MODULOS") | |
private String modulos; | |
public Integer getId() { | |
return id; | |
} | |
public void setId(Integer id) { | |
this.id = id; | |
} | |
public String getDescricao() { | |
return descricao; | |
} | |
public void setDescricao(String descricao) { | |
this.descricao = descricao; | |
} | |
public BigDecimal getValor() { | |
return valor; | |
} | |
public void setValor(BigDecimal valor) { | |
this.valor = valor; | |
} | |
public String getModulos() { | |
return modulos; | |
} | |
public void setModulos(String modulos) { | |
this.modulos = modulos; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.testJunithibernate.projeto.model; | |
import org.hibernate.SessionFactory; | |
import org.hibernate.cfg.Configuration; | |
import org.hibernate.service.ServiceRegistry; | |
import org.hibernate.service.ServiceRegistryBuilder; | |
public class HibernateUtil { | |
private static SessionFactory sessionFactory; | |
private static ServiceRegistry registry; | |
static { | |
try { | |
Configuration configuration = new Configuration().configure().setProperty("hibernate.cfg.xml", "false"); | |
registry= new ServiceRegistryBuilder().applySettings( | |
configuration.getProperties()).buildServiceRegistry(); | |
sessionFactory = configuration.buildSessionFactory(registry); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
public static SessionFactory getSessionFactory(){ | |
return sessionFactory; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment