java.sql.Timestamp with milliseconds


Using JPA with other providers java.util.Date will not provide support to store milliseconds, this can usually be overcome using (see here

@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)


Milliseconds are stored as demonstrated by the following example:

import java.sql.*;

import javax.persistence.*;

public class T1985 {

    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)

Post Reply

To post a reply and/or subscribe to update notifications - please login