Skip to content
Advertisement

how to store date AND time with JPA in Oracle?

I’m using WebSphere 7 (Java EE 5) and OpenJPA 1.2.1.

I have a JPA object with a “modifiedTimestamp” attribute, something like this:

@Entity
public class Widget {
  /* ... */
  private java.sql.Date modifiedTimestamp;
  /* ... */
}

The related field in the Oracle database is of type DATE.

I set the date like so …

myWidget.setModifiedTimestamp(new java.sql.Data(System.currentTimeMillis());

… and it gets stored, but when I read it back the time of day hasn’t been stored, it allows comes back as 24:00.

Is this a JPA thing, or an Oracle thing? Any suggestions are greatly appreciated!

Thanks

Advertisement

Answer

Anotating your field and changing the type should help:

@Temporal(TemporalType.TIMESTAMP)
private java.util.Date modifiedTimestamp;
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement