Hi Thorben, congratulations, and thanks for the explanations, could you share the code, I tried, but instead of remove the relations, I got a "Cannot delete or update a parent row... foreign key..."
@shivendrasaxena21993 жыл бұрын
Thanks for the deep insight Sir. Just a query, would using of OrphanRemoval make things any better ?
@lucasterable3 жыл бұрын
As far as @OneToMany is concerned: The problem is that Hibernate issues delete statements like this: 'DELETE FROM CHILD WHERE *CHILD_ID* = ?'. If the statements were instead like this: 'DELETE FROM CHILD WHERE *PARENT_ID* = ?', or even better, like this: 'DELETE FROM CHILD WHERE *PARENT_ID IN* (?)' then there would be far fewer statements, and performance would improve without the need to manually optimize the SQL schema :/
@ahmadhosny007 жыл бұрын
Hi Thorben. Thanks for the video! I have one concern regarding the IN clause that takes the IDs that should be removed: In JPQL it's limited to 1000 parameters and this broke my code when the deleted IDs list size exceeded that limit. Does the Native query have the same limitation? I made a workaround by using the DB procedures, which led me to having to adapt for all the differences between the various DBs used by our clients, which was a painful operation to perform and maintain.
@Thorben-Janssen7 жыл бұрын
Hi Ahmad, that depends on your database. Oracle, for example, doesn't allow more than 1000 elements in an IN clause. If you run into that issue, you need to perform the remove operation in multiple batches with
@ahmadhosny007 жыл бұрын
I tried to do that, but in fact the default use case was to delete at least 20k lines and the performance degraded dramatically. We were using Oracle like you said but some other clients preferred MS-SQL Server and I didn't even try to use this approach because of the performance difference between the two. Thanks for the reply ;)
@EsJaviCool7 жыл бұрын
Hi Thorben, thanks for this very good video. I've been using CASCADE.REMOVE for one to many, many to one, and even for many to many relationships 'cause I transform them into one to many relationships using an identity entity. Do you think I'm taking a good approach to deal with many to many relationships? I'd really appreciate your anwer :)
@Thorben-Janssen7 жыл бұрын
Hi Esteban, It's hard to give a definitive answer to your question without diving deep into the specific application and its use cases. As long as you transform your many-to-many relationships into 2 one-to-many relationships and you don't experience any performance problems, your approach should be ok. Just be aware, that cascade remove doesn't use the most efficient approach to remove the related entities. You might need to refactor that part if you run into performance problems. Regards, Thorben
@EsJaviCool7 жыл бұрын
Thanks for your answer and advice, I'll take them in account when facing a similar requirement again. Have a good day and thanks a lot for these very useful videos
@arghyamitra32814 жыл бұрын
If cascadeType.remove causing so much problem then why it's there ? Everything in Jpa hibernate is a tweak or hack ... That's why everyone prefer jdbcTemplate
@ylioo4 жыл бұрын
Been wondering the same. I have to optimize every hibernate query with jpql or native queries