Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two day discrepancy with JPA, EclipseLink and SQL Server 2008 R2

When pulling dates from a view using JPA and EclipseLink I'm getting dates two days before the date in the SQL data. (ie 1965-01-01 becomes 1964-12-30 and 1998-12-31 becomes 1998-12-29)

I am mapping date fields in SQL Server 2008 R2 with the following annotations:

@Entity
@Table(name = "vw_Record")
@XmlRootElement
public class VwRecord implements Serializable {
    @Column(name = "dateStart")
    @Temporal(TemporalType.DATE)
    private Date dateStart;

    @Column(name = "dateEnd")
    @Temporal(TemporalType.DATE)
    private Date dateEnd;

The columns in SQL Server are defined as:

[dateStart] [date] NULL,
[dateEnd] [date] NULL

Any ideas why I am getting a consistent two day difference?

like image 549
PaulNBN Avatar asked Dec 03 '25 16:12

PaulNBN


1 Answers

EclipseLink does not do any conversion, it is most likely occurring in JDBC.

You can trying executing a native SQL query through JPA and see what data it returns. Also try selecting the data through raw JDBC.

like image 57
James Avatar answered Dec 06 '25 08:12

James



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!