-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Testcase for invalid_query_key_in_expression
Signed-off-by: Vaibhav Vishal <[email protected]>
- Loading branch information
Showing
7 changed files
with
229 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
...java/org/eclipse/persistence/testing/models/jpa21/advanced/jpql/CarProductionCompany.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...ed2/src/main/java/org/eclipse/persistence/testing/models/jpa21/advanced/jpql/Company.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
...2/src/main/java/org/eclipse/persistence/testing/models/jpa21/advanced/jpql/Continent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
24 changes: 24 additions & 0 deletions
24
...ed2/src/main/java/org/eclipse/persistence/testing/models/jpa21/advanced/jpql/Country.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
19 changes: 19 additions & 0 deletions
19
...in/java/org/eclipse/persistence/testing/models/jpa21/advanced/jpql/ProductionCompany.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...dvanced2/src/test/java/org/eclipse/persistence/testing/tests/advanced2/jpql/JPQLTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |