Giter Site home page Giter Site logo

jodaorg / joda-time-hibernate Goto Github PK

View Code? Open in Web Editor NEW
42.0 11.0 42.0 244 KB

Hibernate mapping for Joda-Time.

Home Page: http://www.joda.org/joda-time-hibernate/

License: Apache License 2.0

Java 97.87% CSS 1.97% HTML 0.16%
java joda joda-time hibernate

joda-time-hibernate's Introduction

Joda-Time Contributions area - Hibernate support
================================================
Joda-Time is a date and time library that vastly improves on the JDK.
This separate project provides Hibernate database persistence support.

See the home page for more details:
http://www.joda.org/joda-time-hibernate/

The source code is held primarily at GitHub:
https://github.com/JodaOrg/joda-time-hibernate

Additional setup
----------------
Joda-Time supports the use of maven for the build process.
Maven tries to download all dependencies from Maven Central.
However, at the time of writing, the Hibernate dependencies are not present.

Add the JBoss repository to you setup to load the dependencies:
https://repository.jboss.org/nexus/content/groups/public-jboss/

See http://www.hibernate.org/ for more details on Hibernate.

joda-time-hibernate's People

Contributors

broneill avatar dependabot[bot] avatar jlleitschuh avatar jodastephen avatar juradoz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

joda-time-hibernate's Issues

PersistentDateTime must implement nullSafeSet

Class 'PersistentDateTime' must either be declared abstract or implement abstract method 'nullSafeSet(PreparedStatement, Object, int, SessionImplementator)' in 'UserType'

<hibernate.version>4.3.8.Final</hibernate.version>
<jodaTime.version>2.7</jodaTime.version>
<jodaTimeHibernate.version>1.4</jodaTimeHibernate.version>

Bad results with PersistentLocalDate for old dates

For dates older than 1891-10-02, PersistentLocalDate gives bad results (value in DB is different then what java reads, and on the other side also written value to DB is different then was stored in java).

Connected to JodaOrg/joda-time#264

Fixed code for PersistentLocalDate (fixing reading from DB and writing to DB):

public class ProperPersistentLocalDate extends PersistentLocalDate {

    private static final long serialVersionUID = -3868992177810711321L;

    @Override
    public Object nullSafeGet(ResultSet resultSet, String string) throws SQLException {
        Object timestamp = StandardBasicTypes.DATE.nullSafeGet(resultSet, string);
        if (timestamp == null) {
            return null;
        }

        //static methods contructions needed for loading proper date from DB
        if (timestamp instanceof Date) {
            return LocalDate.fromDateFields((Date) timestamp);
        } else if (timestamp instanceof Calendar) {
            return LocalDate.fromCalendarFields((Calendar) timestamp);
        }

        return new LocalDate(timestamp);
    }

    @Override
    public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index) throws HibernateException, SQLException {
        if (value == null) {
            StandardBasicTypes.DATE.nullSafeSet(preparedStatement, null, index);
        } else {
            //localDate.toDate() fix for storing proper date in DB (see parent impl for change)
            StandardBasicTypes.DATE.nullSafeSet(preparedStatement, ((LocalDate) value).toDate(), index);
        }
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.