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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:52:20+00:00 2026-06-15T13:52:20+00:00

I need to access an existing MySQL database which uses BIGINT columns to store

  • 0

I need to access an existing MySQL database which uses BIGINT columns to store timestamps:

create table mytable (created bigint);

Now I prefer to work with java.util.Date or java.time.Instant instances instead of integers, so I’m trying to let Hibernate convert the values directly. Unfortunately Hibernate won’t recognize the column when annotated like this:

@Column(name = "created")
private Date created;

or like this:

@Column(name = "created")
@Temporal(TemporalType.TIMESTAMP)
private Calendar created;

This does return something in the future like 2017-07-01T04:14:00+02:00. How can I make Hibernate convert BIGINT columns properly so I don’t have to convert them in getters and setters?

  • 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-15T13:52:21+00:00Added an answer on June 15, 2026 at 1:52 pm

    Hibernate’s TemporalType.TIMESTAMP maps to java.sql.Timestamp. The Timestamp constructor takes Long values which is the number of milliseconds since the epoch. The values in database are stored as Unix timestamps which is the number of seconds since the epoch.

    I wrote a UnixTimestampType that takes seconds instead of milliseconds and creates Date instances:

    public class UnixTimestampType extends AbstractSingleColumnStandardBasicType<Date> implements IdentifierType<Date>, LiteralType<Date> {
        private static final long serialVersionUID = 1L;
        public static final UnixTimestampType INSTANCE = new UnixTimestampType();
    
        public UnixTimestampType() {
            super(UnixTimestampTypeDescriptor.INSTANCE, JdbcDateTypeDescriptor.INSTANCE);
        }
    
        @Override
        public String getName() {
            return "date";
        }
    
        @Override
        public String[] getRegistrationKeys() {
            return new String[] { getName(), java.sql.Date.class.getName() };
        }
    
        @Override
        public String objectToSQLString(Date value, Dialect dialect) throws Exception {
            final java.sql.Date jdbcDate = java.sql.Date.class.isInstance(value) ? (java.sql.Date) value : new java.sql.Date(value.getTime());
            return StringType.INSTANCE.objectToSQLString(jdbcDate.toString(), dialect);
        }
    
        @Override
        public Date stringToObject(String xml) {
            return fromString(xml);
        }
    }
    

    and

    public class UnixTimestampTypeDescriptor implements SqlTypeDescriptor {
        private static final long serialVersionUID = 1L;
        public static final UnixTimestampTypeDescriptor INSTANCE = new UnixTimestampTypeDescriptor();
    
        @Override
        public int getSqlType() {
            return Types.INTEGER;
        }
    
        @Override
        public boolean canBeRemapped() {
            return true;
        }
    
        @Override
        public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
            return new BasicBinder<X>(javaTypeDescriptor, this) {
                @Override
                protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
                    Date date = javaTypeDescriptor.unwrap(value, Date.class, options);
                    date.setTime(date.getTime() / 1000);
                    st.setDate(index, date);
                }
            };
        }
    
        @Override
        public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
            return new BasicExtractor<X>(javaTypeDescriptor, this) {
                @Override
                protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
                    Date date = new Date(rs.getLong(name) * 1000);
                    return javaTypeDescriptor.wrap(date, options);
                }
            };
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to access a RESTful server, which is not created with WCF. For
I want to create two users on my MySQL test database, One with read-only
I am building a Rails application. The application uses MySql as the main database
I need to export data into an Access database. My code works, but it
Is it preferable to store redundant information, (which can be otherwise generated from existing
I am working on a tool which audits access to existing web application. Existing
I have an existing MySQL database schema in production for an PHP5 application. The
I need access to the uint64_t typedef from stdint.h in some wrapper code that
I have two different modules that need access to a single file (One will
I've got an app running maximized in a borderless window and need access to

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.