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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:51:29+00:00 2026-05-20T04:51:29+00:00

I’m using JPA 2.0, more precisely Eclipselink. Here’s my problem: I have an entity

  • 0

I’m using JPA 2.0, more precisely Eclipselink. Here’s my problem:

I have an entity that has a property like “isPaid”. that property is the result of some calculations the entity performs with some of its other fields. since this is derived from other fields, the property does not have a setter method.

As an example, the getter is something like this:

public boolean isPaid() {
  return this.totalAmount - this.amountPaid == 0;
}

that’s just an example. The thing is, I want this property to be calculated and persisted, so i can do a jpql query like:

SELECT d FROM Debt d WHERE d.isPaid = true

Is this possible? Is there any workaround for this?.

I don’t want to retrieve all entities to call this method and then filter those that return true.

  • 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-20T04:51:30+00:00Added an answer on May 20, 2026 at 4:51 am

    Here are a couple of options:

    1) Create a jpql query that directly does what you need:

    select d from Debt d where (d.totalAmount - d.amountPaid) = 0
    

    The benefits of the approach is that it is simple and will always work. The downside is that your query has to understand how the paid logic was calculated.

    2) Create a persisted paid value that stores the calculated value:

    @Basic
    private boolean paid;
    
    public boolean isPaid() {
        return this.paid;
    }
    
    private void updateCalculations() {
        this.paid =  (this.totalAmount - this.amountPaid == 0);
    }
    
    // using int as example here
    public void setTotalAmount(int totalAmount) {
        this.totalAmount = totalAmount;
        updateCalculations();
    }
    public void setAmountPaid(int amountPaid) {
        this.amountPaid = amountPaid;
        updateCalculations();
    }
    

    The benefit of this approach is that you will be able to create a jpql query that directly checks for the boolean value, i.e.,

    select d from Debt d where d.paid = true;
    

    Obviously, the downside to the approach is that you need to make sure to recalculate the value anytime you update the values. However, this can be alleviated if you only calculate it on access. Meaning that in your isPaid() method, you calculate the value, assign it to the paid attribute and then return the value. If you decide to go with this approach, you will need to add a @PrePersist and @PreUpdate method that performs the paid calculation and updates the paid attribute prior to the bean being persisted to the datastore (makes sure that the paid value is always covered.

    If you use JPA annotations on your attributes themselves, you can have a getter without a setter and still be able to correctly retrieve and store the values in the database.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I have thousands of HTML files to process using Groovy/Java and I need to
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but

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.