Skip to content

Commit

Permalink
Recrate #28813
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAure committed Jul 24, 2024
1 parent 1febfef commit c272791
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
<persistence-unit name="RecreatePersistenceUnit">
<properties>
<!-- EclipseLink should create the database schema automatically -->
<property name="jakarta.persistence.schema-generation.database.action" value="drop-and-create" />
<property name="jakarta.persistence.schema-generation.database.action" value="create" />
<property name="eclipselink.logging.parameters" value="true"/>
</properties>
</persistence-unit>
</persistence>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*******************************************************************************
* Copyright (c) 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package io.openliberty.jpa.data.tests.models;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;

/**
* Recreate from io.openliberty.data.internal_fat_jpa
*/
@Entity
public class DemographicInfo {

@Column
public Instant collectedOn;

@GeneratedValue
@Id
public BigInteger id;

@Column
public BigDecimal publicDebt;

@Column
public BigDecimal intragovernmentalDebt;

@Column
public BigInteger numFullTimeWorkers;

public static DemographicInfo of(int year, int month, int day,
long numFullTimeWorkers,
double intragovernmentalDebt, double publicDebt) {
DemographicInfo inst = new DemographicInfo();
inst.collectedOn = ZonedDateTime.of(year, month, day, 12, 0, 0, 0, ZoneId.of("America/New_York")).toInstant();
inst.numFullTimeWorkers = BigInteger.valueOf(numFullTimeWorkers);
inst.intragovernmentalDebt = BigDecimal.valueOf(intragovernmentalDebt);
inst.publicDebt = BigDecimal.valueOf(publicDebt);
return inst;
}

@Override
public String toString() {
return "DemographicInfo from " + collectedOn;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.temporal.ChronoField;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
Expand All @@ -34,6 +37,7 @@
import io.openliberty.jpa.data.tests.models.City;
import io.openliberty.jpa.data.tests.models.CityId;
import io.openliberty.jpa.data.tests.models.Coordinate;
import io.openliberty.jpa.data.tests.models.DemographicInfo;
import io.openliberty.jpa.data.tests.models.NaturalNumber;
import io.openliberty.jpa.data.tests.models.Package;
import io.openliberty.jpa.data.tests.models.Person;
Expand Down Expand Up @@ -650,6 +654,51 @@ public void testOLGH28368() throws Exception {
}
}

@Test // Reference issue: https://github.com/OpenLiberty/open-liberty/issues/28813
public void testOLGH28813() throws Exception {
final ZoneId EASTERN = ZoneId.of("America/New_York");

DemographicInfo US2024 = DemographicInfo.of(2024, 4, 30, 133809000, 7136033799632.56, 27480960216618.32);
DemographicInfo US2023 = DemographicInfo.of(2023, 4, 28, 134060000, 6852746625848.93, 24605068022566.94);
DemographicInfo US2022 = DemographicInfo.of(2022, 4, 29, 132250000, 6526909395140.41, 23847245116757.60);
DemographicInfo US2007 = DemographicInfo.of(2007, 4, 30, 121090000, 3833110332444.19, 5007058051986.64);

tx.begin();
em.persist(US2024);
em.persist(US2023);
em.persist(US2022);
em.persist(US2007);
tx.commit();

List<DemographicInfo> results;

tx.begin();
try {
results = em.createQuery("SELECT o FROM DemographicInfo o WHERE (o.publicDebt BETWEEN ?1 AND ?2) ORDER BY o.publicDebt", DemographicInfo.class)
.setParameter(1, BigDecimal.valueOf(5000000000000.00))
.setParameter(2, BigDecimal.valueOf(10000000000000.00))
.getResultList();
tx.commit();
} catch (Exception e) {
tx.rollback();

/*
* TODO unable to recreate issue
* Exception Description: The object [2007-04-30 11:00:00.0], of class [class java.lang.String],
* from mapping [org.eclipse.persistence.mappings.DirectToFieldMapping[collectedOn-->WLPDemographicInfo.COLLECTEDON]]
* with descriptor [RelationalDescriptor(test.jakarta.data.jpa.web.DemographicInfo --> [DatabaseTable(WLPDemographicInfo)])],
* could not be converted to [class java.time.Instant].
* Internal Exception: java.time.format.DateTimeParseException: Text '2007-04-30 11:00:00.0' could not be parsed at index 10
*/
throw e;
}

assertEquals(1, results.size());
assertEquals(2007, results.get(0).collectedOn.atZone(EASTERN).get(ChronoField.YEAR));

System.out.println(results.get(0).toString());
}

/**
* Utility method to drop all entities from table.
*
Expand Down

0 comments on commit c272791

Please sign in to comment.