Skip to content

Commit

Permalink
Recreate #28931
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAure committed Jul 22, 2024
1 parent 3386553 commit 7ec164c
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*******************************************************************************
* 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 jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;

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

public String name;

@GeneratedValue
@Id
public int id;

@Embedded
public Location location;

public static Business of(float latitude, float longitude, String city, String state, int zip,
int houseNum, String streetName, String streetDir, String name) {
Business inst = new Business();
Street street = new Street(streetName, streetDir);
Address address = new Address(city, state, zip, houseNum, street);

inst.name = name;
inst.location = new Location(address, latitude, longitude);

return inst;
}

@Embeddable
public static class Location {

@Embedded
public Address address;

@Column(columnDefinition = "DECIMAL(8,5) NOT NULL")
public float latitude;

@Column(columnDefinition = "DECIMAL(8,5) NOT NULL")
public float longitude;

public Location() {
}

public Location(Address address, float latitude, float longitude) {
this.address = address;
this.latitude = latitude;
this.longitude = longitude;
}
}

@Embeddable
public static class Address {

public String city;

public int houseNum;

public String state;

@Embedded
public Street street;

public int zip;

public Address() {
}

Address(String city, String state, int zip, int houseNum, Street street) {
this.city = city;
this.state = state;
this.zip = zip;
this.houseNum = houseNum;
this.street = street;
}
}

@Embeddable
public static class Street {

public String direction;

@Column(name = "STREETNAME")
public String name;

public Street() {
}

public Street(String name, String direction) {
this.name = name;
this.direction = direction;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import componenttest.app.FATServlet;
import io.openliberty.jpa.data.tests.models.AsciiCharacter;
import io.openliberty.jpa.data.tests.models.Box;
import io.openliberty.jpa.data.tests.models.Business;
import io.openliberty.jpa.data.tests.models.Coordinate;
import io.openliberty.jpa.data.tests.models.NaturalNumber;
import io.openliberty.jpa.data.tests.models.Person;
Expand Down Expand Up @@ -301,7 +302,40 @@ public void testOLGH28909() throws Exception {
assertEquals(2, wall.length); // 1+1
assertEquals(0, wall.length); // 1-1
assertEquals(2, wall.height); // 1*2
}

@Test
@Ignore("Reference issue: https://github.com/OpenLiberty/open-liberty/issues/28931")
public void testOLGH28931() throws Exception {
Business ibmRoc = Business.of(44.05887f, -92.50355f, "Rochester", "Minnesota", 55901, 2800, "37th St", "NW", "IBM Rochester");
Business ibmRTP = Business.of(35.90481f, -78.85026f, "Durham", "North Carolina", 27703, 4204, "Miami Blvd", "S", "IBM RTP");

Business result;

tx.begin();
em.persist(ibmRoc);
em.persist(ibmRTP);
tx.commit();

tx.begin();
try {
result = em.createQuery("FROM Business WHERE location.address.city=?1 ORDER BY name", Business.class)
.setParameter(1, "Rochester")
.getSingleResult();
tx.commit();
} catch (Exception e) {
tx.rollback();

/*
* Recreate
* Exception Description: Internal problem encountered while compiling [FROM Business WHERE location.address.city=?1 ORDER BY name].
* Internal Exception: java.lang.IndexOutOfBoundsException: Index 1 out of bounds for length 1
*/
throw e;
}

assertEquals("IBM Rochester", result.name);
assertEquals(55901, result.location.address.zip);
}

}

0 comments on commit 7ec164c

Please sign in to comment.