Skip to main content
deleted 11 characters in body
Source Link
SRK
  • 179
  • 1
  • 2
  • 14

One of the Oracle tables looks like this, I dont have the option of changing this:

REPORTING_PERIOD | REPORTING_DATE (Oracle DATE type)
-------------------------------
1140               01-FEB-12
1139               01-JAN-12

The JPA entity (with Hibernate as the provider) which looks like this :

@Column(name="REPORTING_PERIOD")
private long reportingPeriod;

@Temporal( TemporalType.DATE)
@Column(name="REPORT_DATE")
private Date reportDate; //java.util.Date

Now, let us go through my unit tests: (I am using Spring Data JPA for repositories) The below line queries the DB by REPORTING_PERIOD column

ReportingPeriod period1 = reportingPeriodRepository.findByMaxReportingPeriod();
assertNotNull(period1); // works fine and entity is fetched
System.out.println(period1.getReportDate());

The out put of SOP is 2012-02-01 - Notice the automatic conversion from value in db 01-FEB-12

Now, If I query directly by date using '01-FEB-12', as I am doing below, I dont get any results:

ReportingPeriod period2 = reportingPeriodRepository.findByReportDate(period1.getReportDate());
assertNotNull(period2);

Notice that, I am using date field from the same entity which I could successfully fetch in the previous statement.

Nor this works :

DateFormat df = DateFormat.getDateInstancenew SimpleDateFormat(DateFormat.MEDIUM"yyyy-MM-dd");
ReportingPeriod period3 = reportingPeriodRepository.findByReportDate(df.parse("2012-02-01"));
assertNotNull(period3);

Any help on how can I query ( with HQL will also be ok) by REPORTING_DATE as the param when the value in db is 01-FEB-12 is greatly appreciated.

One of the Oracle tables looks like this, I dont have the option of changing this:

REPORTING_PERIOD | REPORTING_DATE (Oracle DATE type)
-------------------------------
1140               01-FEB-12
1139               01-JAN-12

The JPA entity (with Hibernate as the provider) which looks like this :

@Column(name="REPORTING_PERIOD")
private long reportingPeriod;

@Temporal( TemporalType.DATE)
@Column(name="REPORT_DATE")
private Date reportDate; //java.util.Date

Now, let us go through my unit tests: (I am using Spring Data JPA for repositories) The below line queries the DB by REPORTING_PERIOD column

ReportingPeriod period1 = reportingPeriodRepository.findByMaxReportingPeriod();
assertNotNull(period1); // works fine and entity is fetched
System.out.println(period1.getReportDate());

The out put of SOP is 2012-02-01 - Notice the automatic conversion from value in db 01-FEB-12

Now, If I query directly by date using '01-FEB-12', as I am doing below, I dont get any results:

ReportingPeriod period2 = reportingPeriodRepository.findByReportDate(period1.getReportDate());
assertNotNull(period2);

Notice that, I am using date field from the same entity which I could successfully fetch in the previous statement.

Nor this works :

DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
ReportingPeriod period3 = reportingPeriodRepository.findByReportDate(df.parse("2012-02-01"));
assertNotNull(period3);

Any help on how can I query ( with HQL will also be ok) by REPORTING_DATE as the param when the value in db is 01-FEB-12 is greatly appreciated.

One of the Oracle tables looks like this, I dont have the option of changing this:

REPORTING_PERIOD | REPORTING_DATE (Oracle DATE type)
-------------------------------
1140               01-FEB-12
1139               01-JAN-12

The JPA entity (with Hibernate as the provider) which looks like this :

@Column(name="REPORTING_PERIOD")
private long reportingPeriod;

@Temporal( TemporalType.DATE)
@Column(name="REPORT_DATE")
private Date reportDate; //java.util.Date

Now, let us go through my unit tests: (I am using Spring Data JPA for repositories) The below line queries the DB by REPORTING_PERIOD column

ReportingPeriod period1 = reportingPeriodRepository.findByMaxReportingPeriod();
assertNotNull(period1); // works fine and entity is fetched
System.out.println(period1.getReportDate());

The out put of SOP is 2012-02-01 - Notice the automatic conversion from value in db 01-FEB-12

Now, If I query directly by date using '01-FEB-12', as I am doing below, I dont get any results:

ReportingPeriod period2 = reportingPeriodRepository.findByReportDate(period1.getReportDate());
assertNotNull(period2);

Notice that, I am using date field from the same entity which I could successfully fetch in the previous statement.

Nor this works :

DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
ReportingPeriod period3 = reportingPeriodRepository.findByReportDate(df.parse("2012-02-01"));
assertNotNull(period3);

Any help on how can I query ( with HQL will also be ok) by REPORTING_DATE as the param when the value in db is 01-FEB-12 is greatly appreciated.

added 17 characters in body
Source Link
SRK
  • 179
  • 1
  • 2
  • 14

One of the Oracle tables looks like this, I dont have the option of changing this:

REPORTING_PERIOD | REPORTING_DATE (Oracle DATE type)
-------------------------------
1140               01-FEB-12
1139               01-JAN-12

The JPA entity (with Hibernate as the provider) which looks like this :

@Column(name="REPORTING_PERIOD")
private long reportingPeriod;

@Temporal( TemporalType.DATE)
@Column(name="REPORT_DATE")
private Date reportDate; //java.util.Date

Now, let us go through my unit tests: (I am using Spring Data JPA for repositories) The below line queries the DB by REPORTING_PERIOD column

ReportingPeriod period1 = reportingPeriodRepository.findByMaxReportingPeriod();
assertNotNull(period1); // works fine and entity is fetched
System.out.println(period1.getReportDate());

The out put of SOP is 2012-02-01 - Notice the automatic conversion from value in db 01-FEB-12

Now, If I query directly by date using '01-FEB-12', as I am doing below, I dont get any results:

ReportingPeriod period2 = reportingPeriodRepository.findByReportDate(period1.getReportDate());
assertNotNull(period2);

Notice that, I am using date field from the same entity which I could successfully fetch in the previous statement.

Nor this works :

DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
ReportingPeriod period3 = reportingPeriodRepository.findByReportDate(df.parse("2012-02-01"));
assertNotNull(period3);

Any help on how can I query ( with HQL will also be ok) by REPORTING_DATE as the param when the value in db is 01-FEB-12 is greatly appreciated.

One of the Oracle tables looks like this, I dont have the option of changing this:

REPORTING_PERIOD | REPORTING_DATE (Oracle DATE type)
-------------------------------
1140               01-FEB-12
1139               01-JAN-12

The JPA entity (with Hibernate as the provider) which looks like this :

@Column(name="REPORTING_PERIOD")
private long reportingPeriod;

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

Now, let us go through my unit tests: (I am using Spring Data JPA for repositories) The below line queries the DB by REPORTING_PERIOD column

ReportingPeriod period1 = reportingPeriodRepository.findByMaxReportingPeriod();
assertNotNull(period1); // works fine and entity is fetched
System.out.println(period1.getReportDate());

The out put of SOP is 2012-02-01 - Notice the automatic conversion from value in db 01-FEB-12

Now, If I query directly by date using '01-FEB-12', as I am doing below, I dont get any results:

ReportingPeriod period2 = reportingPeriodRepository.findByReportDate(period1.getReportDate());
assertNotNull(period2);

Notice that, I am using date field from the same entity which I could successfully fetch in the previous statement.

Nor this works :

DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
ReportingPeriod period3 = reportingPeriodRepository.findByReportDate(df.parse("2012-02-01"));
assertNotNull(period3);

Any help on how can I query ( with HQL will also be ok) by REPORTING_DATE as the param when the value in db is 01-FEB-12 is greatly appreciated.

One of the Oracle tables looks like this, I dont have the option of changing this:

REPORTING_PERIOD | REPORTING_DATE (Oracle DATE type)
-------------------------------
1140               01-FEB-12
1139               01-JAN-12

The JPA entity (with Hibernate as the provider) which looks like this :

@Column(name="REPORTING_PERIOD")
private long reportingPeriod;

@Temporal( TemporalType.DATE)
@Column(name="REPORT_DATE")
private Date reportDate; //java.util.Date

Now, let us go through my unit tests: (I am using Spring Data JPA for repositories) The below line queries the DB by REPORTING_PERIOD column

ReportingPeriod period1 = reportingPeriodRepository.findByMaxReportingPeriod();
assertNotNull(period1); // works fine and entity is fetched
System.out.println(period1.getReportDate());

The out put of SOP is 2012-02-01 - Notice the automatic conversion from value in db 01-FEB-12

Now, If I query directly by date using '01-FEB-12', as I am doing below, I dont get any results:

ReportingPeriod period2 = reportingPeriodRepository.findByReportDate(period1.getReportDate());
assertNotNull(period2);

Notice that, I am using date field from the same entity which I could successfully fetch in the previous statement.

Nor this works :

DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
ReportingPeriod period3 = reportingPeriodRepository.findByReportDate(df.parse("2012-02-01"));
assertNotNull(period3);

Any help on how can I query ( with HQL will also be ok) by REPORTING_DATE as the param when the value in db is 01-FEB-12 is greatly appreciated.

added 22 characters in body
Source Link
SRK
  • 179
  • 1
  • 2
  • 14

One of the Oracle tables looks like this, I dont have the option of changing this:

REPORTING_PERIOD | REPORTING_DATE (Oracle DATE type)
-------------------------------
1140               01-FEB-12
1139               01-JAN-12

The JPA entity (with Hibernate as the provider) which looks like this :

@Column(name="REPORTING_PERIOD")
private long reportingPeriod;

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

Now, let us go through my unit tests: (I am using Spring Data JPA for repositories) The below line queries the DB by REPORTING_PERIOD column

ReportingPeriod period1 = reportingPeriodRepository.findByMaxReportingPeriod();
assertNotNull(period1); // works fine and entity is fetched
System.out.println(period1.getReportDate());

The out put of SOP is 2012-02-01 - Notice the automatic conversion from value in db 01-FEB-12

Now, If I query directly by date using '01-FEB-12', as I am doing below, I dont get any results:

ReportingPeriod period2 = reportingPeriodRepository.findByReportDate(period1.getReportDate());
assertNotNull(period2);

Notice that, I am using date field from the same entity which I could successfully fetch in the previous statement.

Nor this works :

DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
ReportingPeriod period3 = reportingPeriodRepository.findByReportDate(df.parse("2012-02-01"));
assertNotNull(period3);

Any help on how can I query (HQL with HQL will also be ok) by REPORTING_DATE as the param when the value in db is 01-FEB-12 is greatly appreciated.

One of the Oracle tables looks like this, I dont have the option of changing this:

REPORTING_PERIOD | REPORTING_DATE (Oracle DATE type)
-------------------------------
1140               01-FEB-12
1139               01-JAN-12

The JPA entity (with Hibernate as the provider) which looks like this :

@Column(name="REPORTING_PERIOD")
private long reportingPeriod;

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

Now, let us go through my unit tests: (I am using Spring Data JPA for repositories) The below line queries the DB by REPORTING_PERIOD column

ReportingPeriod period1 = reportingPeriodRepository.findByMaxReportingPeriod();
assertNotNull(period1); // works fine and entity is fetched
System.out.println(period1.getReportDate());

The out put of SOP is 2012-02-01 - Notice the automatic conversion from value in db 01-FEB-12

Now, If I query directly by date using '01-FEB-12', as I am doing below, I dont get any results:

ReportingPeriod period2 = reportingPeriodRepository.findByReportDate(period1.getReportDate());
assertNotNull(period2);

Notice that, I am using date field from the same entity which I could successfully fetch in the previous statement.

Nor this works :

DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
ReportingPeriod period3 = reportingPeriodRepository.findByReportDate(df.parse("2012-02-01"));
assertNotNull(period3);

Any help on how can I query (HQL) by REPORTING_DATE as the param when the value in db is 01-FEB-12 is greatly appreciated.

One of the Oracle tables looks like this, I dont have the option of changing this:

REPORTING_PERIOD | REPORTING_DATE (Oracle DATE type)
-------------------------------
1140               01-FEB-12
1139               01-JAN-12

The JPA entity (with Hibernate as the provider) which looks like this :

@Column(name="REPORTING_PERIOD")
private long reportingPeriod;

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

Now, let us go through my unit tests: (I am using Spring Data JPA for repositories) The below line queries the DB by REPORTING_PERIOD column

ReportingPeriod period1 = reportingPeriodRepository.findByMaxReportingPeriod();
assertNotNull(period1); // works fine and entity is fetched
System.out.println(period1.getReportDate());

The out put of SOP is 2012-02-01 - Notice the automatic conversion from value in db 01-FEB-12

Now, If I query directly by date using '01-FEB-12', as I am doing below, I dont get any results:

ReportingPeriod period2 = reportingPeriodRepository.findByReportDate(period1.getReportDate());
assertNotNull(period2);

Notice that, I am using date field from the same entity which I could successfully fetch in the previous statement.

Nor this works :

DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
ReportingPeriod period3 = reportingPeriodRepository.findByReportDate(df.parse("2012-02-01"));
assertNotNull(period3);

Any help on how can I query ( with HQL will also be ok) by REPORTING_DATE as the param when the value in db is 01-FEB-12 is greatly appreciated.

Source Link
SRK
  • 179
  • 1
  • 2
  • 14
Loading