Advertisement
Guest User

Untitled

a guest
Sep 9th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.52 KB | None | 0 0
  1. @Column(length = 50)
  2. private String descricao;
  3.  
  4.  
  5.  
  6. public Long getCodigo() {
  7. return codigo;
  8. }
  9.  
  10. public void setCodigo(Long codigo) {
  11. this.codigo = codigo;
  12. }
  13.  
  14.  
  15.  
  16. public String getDescricao() {
  17. return descricao;
  18. }
  19.  
  20. public void setDescricao(String descricao) {
  21. this.descricao = descricao;
  22. }
  23.  
  24. private static final SessionFactory sessionFactory = buildSessionFactory();
  25.  
  26. private static SessionFactory buildSessionFactory() {
  27. try {
  28. // Create the SessionFactory from hibernate.cfg.xml
  29. Configuration configuration = new Configuration();
  30. configuration.configure();
  31.  
  32. ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
  33.  
  34. SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
  35.  
  36. return sessionFactory;
  37. }
  38. catch (Throwable ex) {
  39. // Make sure you log the exception, as it might be swallowed
  40. System.err.println("Initial SessionFactory creation failed." + ex);
  41. throw new ExceptionInInitializerError(ex);
  42. }
  43. }
  44.  
  45. public static SessionFactory getSessionFactory() {
  46. return sessionFactory;
  47. }
  48.  
  49. try {
  50. transacao = sessao.beginTransaction();
  51. sessao.save(fabricante);
  52. transacao.commit();
  53. } catch (RuntimeException ex) {
  54. if(transacao != null){
  55. transacao.rollback();
  56. }
  57. throw ex;
  58.  
  59. }finally{
  60. sessao.close();
  61. }
  62.  
  63.  
  64. }
  65.  
  66. <session-factory>
  67.  
  68. <!-- Database connection settings -->
  69. <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
  70. <property name="connection.url">jdbc:mysql://localhost:3306/db_loja</property>
  71. <property name="connection.username">root</property>
  72. <property name="connection.password">123456</property>
  73.  
  74. <!-- JDBC connection pool (use the built-in) -->
  75. <property name="connection.pool_size">1</property>
  76.  
  77. <!-- SQL dialect -->
  78. <property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
  79.  
  80. <!-- Enable Hibernate's automatic session context management -->
  81. <property name="current_session_context_class">thread</property>
  82.  
  83. <!-- Disable the second-level cache -->
  84. <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
  85.  
  86. <!-- Echo all executed SQL to stdout -->
  87. <property name="show_sql">true</property>
  88.  
  89. <!-- Drop and re-create the database schema on startup,*** depois validate-->
  90. <property name="hbm2ddl.auto">validate</property>
  91.  
  92. <mapping class="br.com.loja.domain.Fabricante"/>
  93. <mapping class="br.com.loja.domain.Funcionario" />
  94. <mapping class="br.com.loja.domain.Produto" />
  95. <mapping class="br.com.loja.domain.Cliente" />
  96. <mapping class="br.com.loja.domain.PessoaFisica" />
  97. <mapping class="br.com.loja.domain.PessoaJuridica" />
  98. <mapping class="br.com.loja.domain.Venda" />
  99. <mapping class="br.com.loja.domain.Itens" />
  100.  
  101. </session-factory>
  102.  
  103. Fabricante f2 = new Fabricante();
  104. f2.setDescricao("Robust");
  105.  
  106. FabricanteDAO dao = new FabricanteDAO();
  107. dao.salvar(f1);
  108. dao.salvar(f2);
  109. }
  110.  
  111. <dependencies>
  112. <dependency>
  113. <groupId>org.glassfish</groupId>
  114. <artifactId>javax.faces</artifactId>
  115. <version>2.2.13</version>
  116. </dependency>
  117. <dependency>
  118. <groupId>org.primefaces</groupId>
  119. <artifactId>primefaces</artifactId>
  120. <version>5.3</version>
  121. </dependency>
  122. <dependency>
  123. <groupId>javax</groupId>
  124. <artifactId>javaee-web-api</artifactId>
  125. <version>7.0</version>
  126. <type>jar</type>
  127. </dependency>
  128.  
  129. <dependency>
  130. <groupId>javassist</groupId>
  131. <artifactId>javassist</artifactId>
  132. <version>3.12.1.GA</version>
  133.  
  134. <dependency>
  135. <groupId>junit</groupId>
  136. <artifactId>junit</artifactId>
  137. <version>4.12</version>
  138. <scope>test</scope>
  139. </dependency>
  140.  
  141.  
  142. <dependency>
  143. <groupId>org.hibernate</groupId>
  144. <artifactId>hibernate-validator</artifactId>
  145. <version>5.1.3.Final</version>
  146. </dependency>
  147.  
  148. <dependency>
  149. <groupId>org.hibernate</groupId>
  150. <artifactId>hibernate-core</artifactId>
  151. <version>4.3.6.Final</version>
  152. </dependency>
  153.  
  154. <dependency>
  155. <groupId>mysql</groupId>
  156. <artifactId>mysql-connector-java</artifactId>
  157. <version>5.1.38</version>
  158. </dependency>
  159.  
  160. <dependency>
  161. <groupId>org.primefaces.extensions</groupId>
  162. <artifactId>all-themes</artifactId>
  163. <version>1.0.8</version>
  164. </dependency>
  165.  
  166. </dependencies>
  167. <build>
  168. <pluginManagement>
  169. <plugins>
  170. <plugin>
  171. <groupId>org.apache.maven.plugins</groupId>
  172. <artifactId>maven-compiler-plugin</artifactId>
  173. <version>3.1</version>
  174. <configuration>
  175. <source>1.8</source>
  176. <target>1.8</target>
  177. <compilerArguments>
  178. <endorseddirs>${endorsed.dir}</endorseddirs>
  179. </compilerArguments>
  180. </configuration>
  181. </plugin>
  182. <plugin>
  183. <groupId>org.apache.maven.plugins</groupId>
  184. <artifactId>maven-war-plugin</artifactId>
  185. <version>2.3</version>
  186. <configuration>
  187. <failOnMissingWebXml>false</failOnMissingWebXml>
  188. </configuration>
  189. </plugin>
  190. <plugin>
  191. <groupId>org.apache.maven.plugins</groupId>
  192. <artifactId>maven-dependency-plugin</artifactId>
  193. <version>2.6</version>
  194. <executions>
  195. <execution>
  196. <phase>validate</phase>
  197. <goals>
  198. <goal>copy</goal>
  199. </goals>
  200. <configuration>
  201. <outputDirectory>${endorsed.dir}</outputDirectory>
  202. <silent>true</silent>
  203. <artifactItems>
  204. <artifactItem>
  205. <groupId>javax</groupId>
  206. <artifactId>javaee-endorsed-api</artifactId>
  207. <version>7.0</version>
  208. <type>jar</type>
  209. </artifactItem>
  210. </artifactItems>
  211. </configuration>
  212. </execution>
  213. </executions>
  214. </plugin>
  215. </plugins>
  216. </pluginManagement>
  217. </build>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement