157 words

java.sql.Timestamp with milliseconds

2016-12-06 10:02

Using JPA with other providers java.util.Date will not provide support to store milliseconds, this can usually be overcome using (see here http://docs.oracle.com/javase/1.5.0/docs/api/java/sql/Timestamp.html)

@Column(name = "STMP")
private Timestamp timestamp;

However with ObjectDB the milliseconds are not being stored, as shown this is an ID field and I am encountering duplicate ID errors trying to create multiple entries in the same second.

How can I modify my declaration to include milliseconds ?

I am not particularly attached to using java.sql.Timestamp, but I would like to use a single Date/Time field (ie, not milliseconds since the Epoch)

klonq's picture
Joined on 2016-12-06
User Post #1
2016-12-07 08:03

Milliseconds are stored as demonstrated by the following example:

import java.sql.*;
import javax.persistence.*;
public class F1135 {
    public static void main(String[] args) {
        EntityManagerFactory emf =
        EntityManager em = emf.createEntityManager();
        for (int i = 0; i < 10; i++) {
            em.persist(new MyEntity());
            try { Thread.sleep(20); } catch (InterruptedException x) {}
    public static class MyEntity {
        @Id Timestamp time = new Timestamp(System.currentTimeMillis());
ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support's picture
Joined on 2010-05-03
User Post #2,670

Post Reply

Please read carefully the posting instructions - before posting to the ObjectDB website.

  • You may have to disable pop up blocking in order to use the toolbar (e.g. in Chrome).
  • Use ctrl + right click to open the browser context menu in the editing area (e.g. for using a browser spell checker).
  • To insert formatted lines (e.g. Java code, stack trace) - select a style in the toolbar and then insert the text in the new created block.
  • Avoid overflow of published source code examples by breaking long lines.
  • You may mark in paragraph code words (e.g. class names) with the code style (can be applied by ctrl + D).
  • Long stack traces (> 50 lines) and complex source examples (> 100 lines) should be posted as attachments.
Maximum file size: 32 MB