Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9009491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:12:37+00:00 2026-06-16T02:12:37+00:00

A custom JPA mapper class has a method: removeUser() 1. execute ‘DELETE’ HQL query

  • 0

A custom JPA mapper class has a method:

removeUser()

1. execute 'DELETE' HQL query to remove user
2. call getEntityManager().flush();
3. call getEntityManager().clear();

If I understand clear() correctly, it will remove from context all persistent entities. -source

However, I also read here,

you should define clear architecture- and design guidelines about where a 
clear() can be called. 

What are clear guidelines on when to call clear()?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T02:12:38+00:00Added an answer on June 16, 2026 at 2:12 am

    The articles explains it. Clearing the entity manager empties its associated cache, forcing new database queries to be executed later in the transaction. It’s almost never necessary to clear the entity manager when using a transaction-bound entity manager. I see two reasons to clear:

    • when doing batch processing, in order to avoid having a giant cache eating memory and increasing the time to flush because of long dirty checks
    • when you’re doing DML or SQL queries, which completely bypass the entity manager cache (as in your example). In this case, the state held by the cache doesn’t reflect what is in the database because of the queries, so you want to clear the cache to avoid this inconsistency.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My custom control has the following basic structure: public class NewTextBox : TextBox {
I am able to use Query Cache with Spring Data JPA for my custom
Custom non-fatal exception derive from which class in asp.net 3.5?
I have problems in mapping custom collection with JPA (Hiberante provider). For example when
custom view: public class MyView extends AbstractView { .... awesome stuff ... } controller:
We're building a REST service with Spring and JPA where each method is annotated
My custom type is (no default constructor!): package com.XXX.common; public class Email implements Serializable
Custom Compiler Warnings and C#: Create custom warning in Visual Studio if certain method
I'd like to know how to create my own custom id generator for JPA.
I have class User and class Address. Address contains only 4 property: publiс class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.