1
The change of my DAO is like this:
private EntityManager entityManager;
public void alterar() throws Exception {
System.out.println("T encontrada");
System.out.println("iniciando Alterar id: " + this.getId());
System.out.println("this Class" + this.getClass());
T encontrada = (T) entityManager.find(this.getClass(), this.getId());
System.out.println("encontrada");
try {
System.out.println("Iniciando a transacao de alteracao");
EntityManagerControl.transactionBegin(entityManager);
entityManager.merge(this);
EntityManagerControl.transactionCommit(entityManager);
} catch (Exception e) {
EntityManagerControl.transactionRollback(entityManager);
e.printStackTrace();
} finally {
// manager.close();
}
}
I have records in the database and I have that record saved in the database but at the moment I declare in the Controller object.change(), it from nullPointer in the find command below:
T encontrada = (T) entityManager.find(this.getClass(), this.getId());
How you fix that mistake?
Hello Thiago, all right? How are you building this Entitymanager? Are you using Vraptor, right? If so, did you use @Inject? Are you using a plugin like vraptor-Hibernate or vraptor-jpa? Give us more details about your below :)
– Turini
@Turini actually, I am not using any plugin of these, it is a Maven project, with vRaptor, Hibernate and JPA 2.0, in the other methods as to insert and remove this similar just not have this find(), are running normal and comes to Entitymanager.
– Tiago Ferezin
Put the method code
getId
, must be the problem there.– Jéf Bueno
@Jéfersonbueno, the getId code():
@Override public Long getId() { return this.id;}
– Tiago Ferezin
but where is this Entitymanager being created, Tiago? You can show us this code?
– Turini
Since Ntity was normal, I changed and created a method to exchange for find ta working for now
– Tiago Ferezin