Return-Path: X-Original-To: apmail-openjpa-dev-archive@www.apache.org Delivered-To: apmail-openjpa-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B505910151 for ; Mon, 3 Feb 2014 22:43:07 +0000 (UTC) Received: (qmail 72137 invoked by uid 500); 3 Feb 2014 22:43:06 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 72105 invoked by uid 500); 3 Feb 2014 22:43:05 -0000 Mailing-List: contact dev-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openjpa.apache.org Delivered-To: mailing list dev@openjpa.apache.org Received: (qmail 72095 invoked by uid 99); 3 Feb 2014 22:43:05 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Feb 2014 22:43:05 +0000 Date: Mon, 3 Feb 2014 22:43:05 +0000 (UTC) From: "ASF subversion and git services (JIRA)" To: dev@openjpa.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (OPENJPA-2453) Add support to retain milliseconds of 'un-rounded' Date field. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/OPENJPA-2453?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13890036#comment-13890036 ] ASF subversion and git services commented on OPENJPA-2453: ---------------------------------------------------------- Commit 1564121 from [~fyrewyld] in branch 'openjpa/branches/2.3.x' [ https://svn.apache.org/r1564121 ] OPENJPA-2453: Add support to retain milliseconds of 'un-rounded' Date field. > Add support to retain milliseconds of 'un-rounded' Date field. > -------------------------------------------------------------- > > Key: OPENJPA-2453 > URL: https://issues.apache.org/jira/browse/OPENJPA-2453 > Project: OpenJPA > Issue Type: Improvement > Affects Versions: 2.2.1, 2.3.0 > Reporter: Heath Thomann > Assignee: Heath Thomann > Priority: Minor > > Take the following Entity: > public class TemporalEntity { > @Id > private Integer id; > @Temporal(TemporalType.TIMESTAMP) > private java.util.Date testDate; > ..... > Take this row in the DB (Timestamp is used in the DB): > ID TESTDATE > 1 2010-01-01 12:00:00.687701 > Using a Date, I can not directly get the fractional seconds (i.e. .687701). However, I can use a formatter as follows and the milliseconds will be printed: > TemporalEntity t = em.find(TemporalEntity.class, 1); > SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); > System.out.println("sdf.format(t.getTestDate()) = " + sdf.format(t.getTestDate()).toString()); > E.g: > sdf.format(t.getTestDate()) = 2010-01-01 12:00:00.688 > Notice that the milliseconds are rounded. OpenJPA rounds the milliseconds by default. This rounding was not desirable by some users. For example, take the insert of this data: > INSERT INTO TemporalEntity (Id, testDate) VALUES(1, '9999-12-31 23:59:59.9999') > The Date inserted into the DB is .1 milliseconds from the next day of the next year. When a query is performed on this row, OpenJPA rounds the Date to the nearest millisecond which means the Date seen by the user represents the next day and year. A while back we added a system property ('roundTimeToMillisec', via OPENJPA-2159) to OpenJPA to allow the milliseconds to be stripped off and thus avoid the rounding. So we avoid rounding, but in doing so the milliseconds are completely removed when the property is set. For example, when roundTimeToMillisec=false, the above date of '9999-12-31 23:59:59.9999' will not be rounded up. HOWEVER, the .999 will be stripped off. So, take our String format example above, the output would be: > sdf.format(t.getTestDate()) = 2010-01-01 12:00:00.000 > A user may find it desirable to avoid the rounding, but may not like the fact that .688 is removed. > This JIRA will be used to allow a user to avoid rounding of milliseconds, but will allow the milliseconds to be retained. > Thanks, > Heath Thomann -- This message was sent by Atlassian JIRA (v6.1.5#6160)