This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Help required on the entityManager remove() method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Help required on the entityManager remove() method" Watch "Help required on the entityManager remove() method" New topic

Help required on the entityManager remove() method

Keerthi Kumar Narayan

Joined: Feb 01, 2013
Posts: 5
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

Keerthi Kumar N
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
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.

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


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,

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
Balaji Vankadaru
Ranch Hand

Joined: May 31, 2013
Posts: 48
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.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Help required on the entityManager remove() method
jQuery in Action, 3rd edition