File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA 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
Author

Help required on the entityManager remove() method

Keerthi Kumar Narayan
Greenhorn

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

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.

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


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

Joined: May 31, 2013
Posts: 47
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help required on the entityManager remove() method