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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:38:27+00:00 2026-06-11T19:38:27+00:00

In my Java web application, I have my whole database structure covered by Model

  • 0

In my Java web application, I have my whole database structure covered by Model classes. It’s really neat, because using those models I can very simply print anything from the database directly in the JSP page. See following example:

<c:if test="${fn:length(author.books) == 0}">The author has no books.</c:if>

<c:forEach items="${author.books}" var="book">
${book.name}
</c:forEach>

Model Author has a method getBooks() which fetches related books from the database and returns a collection of models representing books. The problem is that in the example above the method is called actually twice which results in one redundant query.

I know that I can store the value using <c:set /> but firstly, I would have use that a lot (the example above is quite common in my app) and secondly, it doesn’t always work. For example:

<c:forEach items="${books}" var="book">
${book.author.name}
</c:forEach>

My database unfortunately doesn’t support joins so that for each line I have to run a query to fetch the author from the database (it’s actually pretty fast, because authors are stored in memcache by keys). And let’s say I want to use this loop twice in one page (big menu and small menu or whatever…). So each author is fetched twice from database (or memcache) and that is really not desired.

How do I avoid that? Ideally, the JSP “renderer” should each acquired value store in a temporary cache (just for one request) and next time use this cached value instead of calling the method again. Another way would be to implement this cache directly in the model objects but I don’t know how to do that efficiently without rewriting half of my code. Any ideas?

  • 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-11T19:38:28+00:00Added an answer on June 11, 2026 at 7:38 pm

    The biggest problem was with the second described example – I wanted to avoid repetitive fetching of the same entities from the datastore (or memcache). Luckily, all entities are fetched in a completely separated layer. I updated this layer so that now every fetched entity is stored in a HashMap by its key. This HashMap is used as a simple cache – when one entity is demanded more than once, it is fetched only in the first case, after that cached value is used. This HashMap is cleared when the request is finished.

    This is more likely a workaround than a real solution I am still interested in other ideas.

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

Sidebar

Related Questions

I have a java web application which I can debug using IntelliJ or Eclipse
I have a Java based web-application using Java Server Faces and Facelets. I am
I have a fairly standard Java EE6 web application using JPA 2 with dependency
For our Kunagi Java web application we have a signed kunagi.jar file which contains
I have a Java web application at my work and I'd like simplify how
i have three java based web application app1,app2 and app3 at production. All 3
I have a Java EE web application (WebSphere 7). The code looks up EJBs
I have a Java-JSF Web Application on GlassFish, in which I want to use
I have a Java Web Start application. I specify the resource (jars, images, etc)
Is it possible to have a Java/J2EE web application integrate/communicate with SharePoint to load,

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.