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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:32:48+00:00 2026-05-27T19:32:48+00:00

my problem is that when I do a query on the database with a

  • 0

my problem is that when I do a query on the database with a order by startTime where the startTime is a Joda time, it is returning the times starting at 4pm.

Now, 4pm is exactly 8 hours away from 12 midnight, and coincidentally I live in Hong Kong and that is my time zone and Hong Kong timezone is 8 hours from midnight.

My startTime JPA field is:

@Index(name = "bookingStartTimeIndex")
@Column(name = "start_time")
@Type(type="org.joda.time.contrib.hibernate.PersistentLocalTimeAsTime")
private LocalTime startTime;

I use JPA/Hibernate and my query is basically to select * where:

order by b.startTime asc

Now I have entities with times from 9am to 6pm stored in this table. What comes back from this “order by” is entities starting with time 4pm going to 6pm then at 9am to 4pm.
So it looks like it has decided that 4pm is midnight somehow.

This is a postgresql database, when I look at my database colum has a datatype of time_without_time_zone.

So how can I get it to order the entities normally from 9am to 6pm?


A workaround I found is to change to use PersistentLocalTimeExact, this works for
me under the conditions I have mentioned and solves all the problems I had with 4pm…

@Index(name = “bookingStartTimeNumberIndex”)
@Column(name = “start_time_number”, nullable = true)
@Type(type=”org.joda.time.contrib.hibernate.PersistentLocalTimeExact”)
private LocalTime startTimeNumber;

  • 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-27T19:32:49+00:00Added an answer on May 27, 2026 at 7:32 pm

    This sounds like an issue of data presentation rather than a fundamental problem, though it is a little unclear.

    Are you saying that for a record in the database that has a time of 0:00 hours it displays as 16:00 hours when you get it back from the database? If so, then I think there’s some confusion over reading the date from the database and somewhere in Hibernate extension for Joda Time is creating the LocalTime instance assuming the database time is UTC and then creating an instance of LocalTime with your local timezone, thus applying a -8 hour offset.

    As Erwin says, storing a timezone in the database is the better way to go, or if you can’t do that then only store UTC dates and/or times.

    I had a look at the Joda Time website and they are recommending a different Hibernate extension as better supported than the original one you are using.

    You can also try breakpointing the PersistentLocalTimeAsTime class and see how the LocalTime is being constructed.

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

Sidebar

Related Questions

Possible Duplicate: SQL Server Database query help Hi, I have a problem that I
I have a problem that I would like have solved via a SQL query.
This is a query that is executed without problem with MySql 5.0.51: SELECT cc_split.idSplit,
I have the following query of linq to entities. The problem is that it
I have been struggling with a problem that only happens when the database has
My problem : I got a MySQL database that stores a great amount of
i have an application where i order make a query to my database with
I am running in very strange date range query problem. When I use DateTime.now.utc
I've a query that works OK against a MySQL database, but we've had to
I have code that runs a query on the database and returns some data

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.