File tree Expand file tree Collapse file tree 1 file changed +10
-9
lines changed
src/main/java/dev/emanoel/modulo02/teste Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change 1
1
package dev .emanoel .modulo02 .teste ;
2
2
3
+ import dev .emanoel .modulo02 .dao .ProdutoDAO ;
3
4
import dev .emanoel .modulo02 .model .Produto ;
5
+ import dev .emanoel .modulo02 .util .JPAUtil ;
4
6
5
7
import javax .persistence .EntityManager ;
6
- import javax .persistence .EntityManagerFactory ;
7
- import javax .persistence .Persistence ;
8
8
import java .math .BigDecimal ;
9
9
10
10
public class CadastroProdutoTeste {
11
11
12
12
public static void main (String [] args ) {
13
13
14
14
Produto produto = new Produto ();
15
- produto .setNome ("controle " );
16
- produto .setDescricao ("controle xbox " );
17
- produto .setPreco (new BigDecimal ("300 " ));
15
+ produto .setNome ("headset " );
16
+ produto .setDescricao ("headset preto " );
17
+ produto .setPreco (new BigDecimal ("150 " ));
18
18
19
- EntityManagerFactory entityManagerFactory = Persistence . createEntityManagerFactory ( "loja" );
19
+ EntityManager entityManager = JPAUtil . getEntityManager ( );
20
20
21
- EntityManager entityManager = entityManagerFactory . createEntityManager ( );
21
+ ProdutoDAO produtoDAO = new ProdutoDAO ( entityManager );
22
22
23
23
entityManager .getTransaction ().begin ();
24
- entityManager . persist (produto );
24
+ produtoDAO . cadastrar (produto );
25
25
entityManager .getTransaction ().commit ();
26
- entityManager .clear ();
26
+ entityManager .close ();
27
+
27
28
}
28
29
}
You can’t perform that action at this time.
0 commit comments