-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Não remove Objeto JPA2 , JAVA
PostPosted: Thu Jan 01, 2015 2:09 pm 
Newbie

Joined: Thu Jan 01, 2015 1:57 pm
Posts: 1
EntityManager ?

O banco de dados ta assim no wokbanch: (nomes ficticios)
tentei remover o id "1" e o id "2" , mas quando listei nao tinha removido , alguem sabe pq ?

id email nome
1 saraivaarrobagmail.com saraiva
2 editoraxxarrobagmail.com editoraxx
3 editorazzzarrobahotmail.com editorazz

Code:
package test;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import model.Editora;

public class RemoverObjeto {

   public static void main(String[] args) {
      EntityManagerFactory factory = Persistence.createEntityManagerFactory("livraria");
      EntityManager manager = factory.createEntityManager();
     
      Editora editora1 = manager.find (Editora.class , 1L); // no ID 1 sera removido a editora no caso "saraiva" 1L
      manager.remove(editora1);
     
      Editora editora2 = manager.find(Editora.class, 2L); // no 2 3 sera removido a editora no caso " editoraxx" 2L
      manager.remove(editora2); 
     
      System.out.println("removido: "+ editora2.getNome());
      System.out.println("removido: "+ editora1.getNome());
     
   }
}



Code:
package test;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;

import model.Editora;

public class ListaEditoraComJPA {

   public static void main(String[] args) {
      EntityManagerFactory factory = Persistence.createEntityManagerFactory("livraria");
      EntityManager manager = factory.createEntityManager();
     
      Query query = manager.createQuery("SELECT e FROM Editora e"); 
      List<Editora>editoras = query.getResultList();
     
      for(Editora e: editoras){
         System.out.println("Editora: "+e.getNome()+" - "+e.getId());
      }
         
   }
}




Depois da remocao listando o banco de dados, e ainda continuam os mesmos objetos: pq ?

id email nome
1 saraivaarrobagmail.com saraiva
2 editoraxxarrobagmail.com editoraxx
3 editorazzzarrobahotmail.com editorazz


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.