Skip to content

Commit

Permalink
Testcase for invalid_query_key_in_expression
Browse files Browse the repository at this point in the history
Signed-off-by: Vaibhav Vishal <[email protected]>
  • Loading branch information
vavishal committed Mar 4, 2025
1 parent 9fee2b3 commit 096f057
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2025 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
package org.eclipse.persistence.testing.models.jpa21.advanced.jpql;

import jakarta.persistence.Entity;

@Entity
public class CarProductionCompany extends ProductionCompany {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2025 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
package org.eclipse.persistence.testing.models.jpa21.advanced.jpql;

import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;

@Entity
@Table(name = "JPA21_COMPANY")
public class Company {

@Id
Long companyKey;

@ManyToOne
Country originCountry;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2025 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
package org.eclipse.persistence.testing.models.jpa21.advanced.jpql;

import java.util.List;

import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;

@Entity
@Table(name = "JPA21_CONTINENT")
public class Continent {

@Id
private long continentKey;

@OneToMany
List<Country> countries;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2025 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
package org.eclipse.persistence.testing.models.jpa21.advanced.jpql;

import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

@Entity
@Table(name = "JPA21_COUNTRY")
public class Country {

@Id
private long countryKey;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2025 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
package org.eclipse.persistence.testing.models.jpa21.advanced.jpql;

import jakarta.persistence.Entity;

@Entity
public class ProductionCompany extends Company {

}
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,19 @@
<property name="jakarta.persistence.schema-generation.database.action" value="drop-and-create"/>
</properties>
</persistence-unit>

<persistence-unit name="pu-jpql" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>org.eclipse.persistence.testing.models.jpa21.advanced.jpql.CarProductionCompany</class>
<class>org.eclipse.persistence.testing.models.jpa21.advanced.jpql.Company</class>
<class>org.eclipse.persistence.testing.models.jpa21.advanced.jpql.Continent</class>
<class>org.eclipse.persistence.testing.models.jpa21.advanced.jpql.Country</class>
<class>org.eclipse.persistence.testing.models.jpa21.advanced.jpql.ProductionCompany</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<shared-cache-mode>DISABLE_SELECTIVE</shared-cache-mode>
<properties>
<property name="jakarta.persistence.schema-generation.database.action" value="drop-and-create"/>
</properties>
</persistence-unit>

</persistence>
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright (c) 2025 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
package org.eclipse.persistence.testing.tests.advanced2.jpql;

import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;

import junit.framework.Test;
import junit.framework.TestSuite;

import org.eclipse.persistence.testing.framework.jpa.junit.JUnitTestCase;
import org.eclipse.persistence.testing.models.jpa21.advanced.jpql.CarProductionCompany;
import org.eclipse.persistence.testing.models.jpa21.advanced.jpql.Company;
import org.eclipse.persistence.testing.models.jpa21.advanced.jpql.Continent;
import org.eclipse.persistence.testing.models.jpa21.advanced.jpql.ProductionCompany;

public class JPQLTest extends JUnitTestCase {

public JPQLTest() {
}

public JPQLTest(String name) {
super(name);
setPuName(getPersistenceUnitName());
}

@Override
public String getPersistenceUnitName() {
return "pu-jpql";
}

public static Test suite() {
TestSuite suite = new TestSuite();
suite.setName("JPQLTest");
suite.addTest(new JPQLTest("testJPQLs"));
return suite;
}

public void testJPQLs() {
EntityManagerFactory emf = getEntityManagerFactory();
EntityManager em = createEntityManager();
beginTransaction(em);
try {
String jpql = "SELECT continent"
+ " FROM Continent continent "
+ " WHERE NOT EXISTS (SELECT c FROM Company c WHERE c.originCountry MEMBER OF continent.countries)";
em.createQuery(jpql, Object[].class).getResultList();

jpql = "SELECT continent"
+ " FROM Continent continent "
+ " WHERE NOT EXISTS (SELECT c FROM ProductionCompany c WHERE c.originCountry MEMBER OF continent.countries)";
em.createQuery(jpql, Object[].class).getResultList();

jpql = "SELECT continent"
+ " FROM Continent continent "
+ " WHERE NOT EXISTS (SELECT c FROM CarProductionCompany c WHERE c.originCountry MEMBER OF continent.countries)";
em.createQuery(jpql, Object[].class).getResultList();
} finally {
if (this.isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
}
}

@Override
public void tearDown() {
EntityManager em = createEntityManager();
em.getTransaction().begin();
try {
em.createQuery("delete from CarProductionCompany c").executeUpdate();
em.createQuery("delete from Company d").executeUpdate();
em.createQuery("delete from Continent e").executeUpdate();
em.createQuery("delete from Country f").executeUpdate();
em.createQuery("delete from ProductionCompany p").executeUpdate();
commitTransaction(em);
} finally {
if (this.isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
}
}
}

0 comments on commit 096f057

Please sign in to comment.