• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help required on the entityManager remove() method

 
Keerthi Kumar Narayan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

I am currently working on the CRUD operation using JPA. While deleting an entity from the database, it is consuming a bit long time to complete the transaction. I have used entityManager.remove(entity) api. Since, the entity which I need to delete is having relation with other entities, all the references needs with those entities need to be deleted and hence it is taking so much of time. So is there any performance tricks can I implement to faster this deletion process?

Please help me

Thanks,
Keerthi Kumar N
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would start by getting an SQL log of what is really occurring (log level to FINE if using EclipseLink).

If you are deleting a lot of the same types of objects, batch writing may help.

http://java-persistence-performance.blogspot.com/2013/05/batch-writing-and-dynamic-vs.html

Otherwise, if you are deleting a dependency tree you could try CASCADE DELETE on the database.

See,
http://wiki.eclipse.org/EclipseLink/Examples/JPA/DeleteCascade

EclipseLink also has a @DeleteAll optimization for private OneToMany relationships.

If you are deleting a large batch of objects, you could use a JPQL bulk delete,

http://en.wikibooks.org/wiki/Java_Persistence/JPQL#Delete_Queries
 
Balaji Vankadaru
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The easiet way to achieve to deal is like you can have an cascade attribute defined where you establishing the relation. What cascade facilitates us when you have one to many relation ship between classes and the change made to the column need to be reflected among its dependencies is managed by cascade with ease. Cascade comes up with Cascade delete , save , update or delete orphan.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic