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 3216584
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:18:42+00:00 2026-05-17T15:18:42+00:00

I am developpng a simple web service: void deleteCar(int idCar) Currently, what I am

  • 0

I am developpng a simple web service:
void deleteCar(int idCar)

Currently, what I am doing in my code is :
1 – load the car Object by id :session.get(Car.class,idCar)
2 – remove it : session.delete(carLoaded)

So for an operation I have at least 2 sql query (n+1 problem ?)
I don’t even speak about any not lazy relationship in the car that will result in more SQL queries.

I thought that to use an HQL query:
1 – will check by the id if the car exist with a lockMode.UPGRADE (boolean carDao.exist(int id))
2 – if the car exist, use a hql query like this one :”delet from Car c where c.id=?”

But how the cache might react to this (we will use ehCache)

In the first solution, I’m almost sure the car will be evicted from the 2nd level cache.

In the 2nd solution( with hql query), will the cache be smart enough to remove the car loaded in the 2nd level cache?

  • 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-05-17T15:18:43+00:00Added an answer on May 17, 2026 at 3:18 pm

    So for an operation i have at least 2 sql query (n+1 problem ?)

    The N+1 problem occurs when you retrieve N entities (with 1 query) and need to perform an additional query per entity (N in total) to fetch something. That’s not really the case here.

    I don’t even speak about any not lazy relationship in the car that will result in more sql queries.

    Well, if you have a graph of objects, you’ll need several delete queries. Aren’t you happy that Hibernate can cascade them for you?

    I have thought to use an HQL query that (…)

    Firstly, I don’t really see the point of the first select (I thought you wanted to limit the number of queries).

    Secondly, a bulk HQL DELETE would indeed save a SELECT but it doesn’t cascade to related entities which might be a problem in your case (so you’ll have to handle relations yourself, if possible).

    Not sure it will suit your needs.

    But how the cache might react to this

    Hibernate will invalidate needed region(s) upon completion of a “bulk Operation”.

    See Bulk Operations for details and recommendation about their use.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently developing a very simple web service and thought I could write
I'm developing a simple web service using MS Visual Studio 2008, C# and .net
Now on my localhost I'm starting developing first simple web service using ruby 1.9.2
I'm developing a simple web service and client. See my snippet of service: @webService
For a web service I'm developing I would like my embedded code (on the
I am developing a simple web service with Spring 3.1.3 and spring ws-2.1.1. My
I am developing a simple spring REST web service. From the research I did
I'm currently developing a REST web service using Web API . I have encountered
I'm trying to develop a simple web service using Recess , which is a
I'm developing simple Windows Service sending and receiving data from remote web service. I

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.