-->
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.  [ 3 posts ] 
Author Message
 Post subject: Delete object
PostPosted: Mon Dec 19, 2005 8:12 am 
Newbie

Joined: Thu Oct 20, 2005 8:30 am
Posts: 10
Hello to everybody!!I'm not getting to delete:
Code:
public void apaga (Estoque estoque){
  try{
     Session sessao = HibernateUtil.getSession();
     sessao.beginTransaction();
     sessao.delete(estoque);
     sessao.flush();
     HibernateUtil.commitTransaction();
  }catch (HibernateException ex){ex.printStackTrace();}

The only thing that happens is that the values become null, only the id keep the value!!!

The other part where I try to delete the object!!
Code:
Estoque estoq = new Estoque();
EstoqueDAO estoqDao = new EstoqueDAO();
estoq.setId(new Long (2));
estoqDao.apaga(estoq);


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 19, 2005 1:47 pm 
Beginner
Beginner

Joined: Sat Dec 17, 2005 1:24 pm
Posts: 42
Location: Berlin, Germany
Hi!

I assume, that the reason, that your delete() does not work is, that Session.delete() expects a persistent object. The object estoq in your example is not linked with Hibernate. The following (in pseudo code) should work:

Code:
EstoqueDAO estoqDao = new EstoqueDAO();
Estoque estoqDao estoq = estoqDao.get(new Long(2));
estoqDao.delete(estoq);


Of course, get() and delete() should be in the same transaction!
Did that help?

All the best,

René


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 6:44 am 
Newbie

Joined: Thu Oct 20, 2005 8:30 am
Posts: 10
Hi, I resolved the problem, it's because didn't have done the commit and didn't close de session!!But, thanks a lot!!


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

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.