jodaorg / joda-time-hibernate Goto Github PK
View Code? Open in Web Editor NEWHibernate mapping for Joda-Time.
Home Page: http://www.joda.org/joda-time-hibernate/
License: Apache License 2.0
Hibernate mapping for Joda-Time.
Home Page: http://www.joda.org/joda-time-hibernate/
License: Apache License 2.0
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.
I have outlined the issue in this blog post:
http://mnmlst-dvlpr.blogspot.de/2013/11/joda-time-to-jdbc-in-three-hard-lessons.html
In short: Relying on the default time zone when converting from partial to instant is not safe.
How about this?
I'd like to use this project with the latest joda-time. Is there any plan to accept any such contribution?
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>
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);
}
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.