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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:27:10+00:00 2026-05-23T01:27:10+00:00

This questions concerns the use of the formula field in a static mapping block

  • 0

This questions concerns the use of the formula field in a static mapping block in Grails.

I am trying to implement a very simple domain class that uses a formula mapping (derived properties), but I keep getting a “No property found for name [uptime]“, where uptime is a derived property in the Grails domain class. The code is as follows (simplified):

class Derive {
  Integer up
  Integer down

  static mapping = {
    uptime formula : "UP/(DOWN+UP)"
  }
}

class DeriveTests extends GroovyTestCase {

    void testDerivedProp() {
      new Derive(up:10, down:5).save()
      new Derive(up:5, down:5).save()
      assertEquals Derive.all.size(),2

      assertEquals 2,Derive.findAllByUptimeGreaterThan(0.1).size() //fails here
      assertEquals 2,Derive.findAllByUptimeGreaterThan(10/(10+5)).size()
    }
}

Running the test gives me an error at the second assertEquals: org.codehaus.groovy.grails.exceptions.InvalidPropertyException: No property found for name [uptime] for class [class Derive]. I cannot see what I am doing wrong here, having consulted both Grails In Action and the reference docs several times.

Any clues as to what I am doing wrong? The backing db is a HSQLDB running in memory with default settings (created by grails create-app).

edit: I am a bit unsure whether I should add a property field for the formula or not. If I do add a property field ‘Double uptime’, the assert still fails, but this time because uptime is 0. Viewing the object in a debugger show that uptime is null. Still, the sql output shows me something that looks right: hibernate.SQL select this_.id as id6_0_, this_.version as version6_0_, this_.down as down6_0_, this_.up as up6_0_, this_.UP*100/(this_.DOWN+this_.UP) as formula0_0_ from derive this_

  • 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-23T01:27:11+00:00Added an answer on May 23, 2026 at 1:27 am

    No new answers in a while, so I am posting a sum-up:

    • There has to be a field for the formula in order for it to work.
    • The derived property is always searchable, as this involved a database search, but the property of an object will always be null if the version that was saved is still in the cache. In short: clear the session cache before search or refresh the cached object (obj.refresh())

    The last bit, manually refreshing, seems very unelegant, but I have not found a way around it.

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

Sidebar

Related Questions

I am aware of this question , but I believe my concerns are very
I've read some of the questions regarding anemic domain models and separation of concerns.
I have a question that is similar to this question , but mine concerns
This questions is a follow up on an answer by Paul Alexander to the
This questions involves 2 different implementations of essentially the same code. First, using delegate
This questions relating to infowindow in the google maps API v3.. Currently I loop
I've seen this questions here . I'm wondering if there exists an official name
This is homework, and this questions Extends this one So there is a button
Hi I found this questions How to manipulate WPF GUI based on user roles
I believe this questions has been asked in some or the other way 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.