Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Column(length = 50)
- private String descricao;
- public Long getCodigo() {
- return codigo;
- }
- public void setCodigo(Long codigo) {
- this.codigo = codigo;
- }
- public String getDescricao() {
- return descricao;
- }
- public void setDescricao(String descricao) {
- this.descricao = descricao;
- }
- private static final SessionFactory sessionFactory = buildSessionFactory();
- private static SessionFactory buildSessionFactory() {
- try {
- // Create the SessionFactory from hibernate.cfg.xml
- Configuration configuration = new Configuration();
- configuration.configure();
- ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
- SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
- return sessionFactory;
- }
- catch (Throwable ex) {
- // Make sure you log the exception, as it might be swallowed
- System.err.println("Initial SessionFactory creation failed." + ex);
- throw new ExceptionInInitializerError(ex);
- }
- }
- public static SessionFactory getSessionFactory() {
- return sessionFactory;
- }
- try {
- transacao = sessao.beginTransaction();
- sessao.save(fabricante);
- transacao.commit();
- } catch (RuntimeException ex) {
- if(transacao != null){
- transacao.rollback();
- }
- throw ex;
- }finally{
- sessao.close();
- }
- }
- <session-factory>
- <!-- Database connection settings -->
- <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
- <property name="connection.url">jdbc:mysql://localhost:3306/db_loja</property>
- <property name="connection.username">root</property>
- <property name="connection.password">123456</property>
- <!-- JDBC connection pool (use the built-in) -->
- <property name="connection.pool_size">1</property>
- <!-- SQL dialect -->
- <property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
- <!-- Enable Hibernate's automatic session context management -->
- <property name="current_session_context_class">thread</property>
- <!-- Disable the second-level cache -->
- <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
- <!-- Echo all executed SQL to stdout -->
- <property name="show_sql">true</property>
- <!-- Drop and re-create the database schema on startup,*** depois validate-->
- <property name="hbm2ddl.auto">validate</property>
- <mapping class="br.com.loja.domain.Fabricante"/>
- <mapping class="br.com.loja.domain.Funcionario" />
- <mapping class="br.com.loja.domain.Produto" />
- <mapping class="br.com.loja.domain.Cliente" />
- <mapping class="br.com.loja.domain.PessoaFisica" />
- <mapping class="br.com.loja.domain.PessoaJuridica" />
- <mapping class="br.com.loja.domain.Venda" />
- <mapping class="br.com.loja.domain.Itens" />
- </session-factory>
- Fabricante f2 = new Fabricante();
- f2.setDescricao("Robust");
- FabricanteDAO dao = new FabricanteDAO();
- dao.salvar(f1);
- dao.salvar(f2);
- }
- <dependencies>
- <dependency>
- <groupId>org.glassfish</groupId>
- <artifactId>javax.faces</artifactId>
- <version>2.2.13</version>
- </dependency>
- <dependency>
- <groupId>org.primefaces</groupId>
- <artifactId>primefaces</artifactId>
- <version>5.3</version>
- </dependency>
- <dependency>
- <groupId>javax</groupId>
- <artifactId>javaee-web-api</artifactId>
- <version>7.0</version>
- <type>jar</type>
- </dependency>
- <dependency>
- <groupId>javassist</groupId>
- <artifactId>javassist</artifactId>
- <version>3.12.1.GA</version>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.12</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-validator</artifactId>
- <version>5.1.3.Final</version>
- </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-core</artifactId>
- <version>4.3.6.Final</version>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>5.1.38</version>
- </dependency>
- <dependency>
- <groupId>org.primefaces.extensions</groupId>
- <artifactId>all-themes</artifactId>
- <version>1.0.8</version>
- </dependency>
- </dependencies>
- <build>
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>3.1</version>
- <configuration>
- <source>1.8</source>
- <target>1.8</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>
- </pluginManagement>
- </build>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement