• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

is better to load instance before delete it?

 
Leandro Coutinho
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! I load instances before delete it, I mean:
MyClass instance = dao.read(id);
dao.delete(instance);

But I saw an example that he simply do this:
dao.delete(new MyClass(id));

It's simpler, and it has better performance. My doubt is if there is some problem using this approach.
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure if you friend's code will work.


You need to retrieve the persistent object first. If you use session.load(), you will only get a proxy object and thus no database hit will occur. Then use that proxy object to delete the instance.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic