ObjectDB ObjectDB

Calculating age in query?

#1

Hi!

I've got an issue: I have a birthdate as java.sql.Date and a separate field int age. However, of course the age is not accurate because it gets set only once. So what's the best bet (JPA Standard way) to solve the issue of accessing and filtering by an age (having a birthdate) in a query?

thanks!

Alex

edit
delete
#2

You can use a JPQL query with a simple date comparison:

SELECT p FROM Person p WHERE p.birthDate BETWEEN :FROM AND :TO

The values for the FROM and TO parameters can be calculated just before query execution.

ObjectDB Support
edit
delete

Reply

To post on this website please sign in.