forked from eclipse-ee4j/eclipselink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue eclipse-ee4j#1727 - Added test case.
Signed-off-by: Tomáš Kraus <tomas.kraus@oracle.com>
- Loading branch information
1 parent
140718f
commit 944b4f4
Showing
2 changed files
with
133 additions
and
4 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
...pselink.jpa.test.jse/src/it/java/org/eclipse/persistence/jpa/test/jpql/TestBasicJPQL.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,108 @@ | ||
/* | ||
* Copyright (c) 2022 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 | ||
*/ | ||
|
||
// Contributors: | ||
// 10/11/2022-4.0 Tomas Kraus | ||
// - Issue #1727: Error execution delete operation without identification_variable | ||
package org.eclipse.persistence.jpa.test.jpql; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.EntityManagerFactory; | ||
import jakarta.persistence.PersistenceException; | ||
import jakarta.persistence.Query; | ||
import org.eclipse.persistence.jpa.test.framework.DDLGen; | ||
import org.eclipse.persistence.jpa.test.framework.Emf; | ||
import org.eclipse.persistence.jpa.test.framework.EmfRunner; | ||
import org.eclipse.persistence.jpa.test.jpql.model.SimpleEntity; | ||
import org.eclipse.persistence.logging.AbstractSessionLog; | ||
import org.eclipse.persistence.logging.SessionLog; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(EmfRunner.class) | ||
public class TestBasicJPQL { | ||
|
||
@Emf(createTables = DDLGen.DROP_CREATE, | ||
classes = {SimpleEntity.class}) | ||
private EntityManagerFactory emf; | ||
|
||
private final SimpleEntity[] ENTITY = { | ||
new SimpleEntity( | ||
"SimpleDeleteNoAlias", "DeleteNoAlias1", "DeleteNoAlias2", | ||
"DeleteNoAlias3", "DeleteNoAlias4", 1,2) | ||
}; | ||
|
||
@Before | ||
public void setup() { | ||
final EntityManager em = emf.createEntityManager(); | ||
try { | ||
em.getTransaction().begin(); | ||
for (SimpleEntity e : ENTITY) { | ||
em.persist(e); | ||
} | ||
em.flush(); | ||
em.getTransaction().commit(); | ||
} catch (Throwable t) { | ||
AbstractSessionLog.getLog().logThrowable(SessionLog.WARNING, t); | ||
throw t; | ||
} finally { | ||
if (em.getTransaction().isActive()) { | ||
em.getTransaction().rollback(); | ||
} | ||
em.close(); | ||
} | ||
} | ||
|
||
@After | ||
public void cleanup() { | ||
final EntityManager em = emf.createEntityManager(); | ||
try { | ||
em.getTransaction().begin(); | ||
for (SimpleEntity e : ENTITY) { | ||
try { | ||
em.remove(e); | ||
} catch (PersistenceException pe) { | ||
AbstractSessionLog.getLog().log( | ||
SessionLog.FINEST, "Could nod delete entity: " + pe.getMessage()); | ||
} | ||
} | ||
em.flush(); | ||
em.getTransaction().commit(); | ||
} finally { | ||
if (em.getTransaction().isActive()) { | ||
em.getTransaction().rollback(); | ||
} | ||
em.close(); | ||
} | ||
} | ||
|
||
// Issue #1727 - Error execution delete operation without identification_variable | ||
@Test | ||
public void testDeleteEntityWithoutAlias() { | ||
final String jpql = "DELETE FROM SimpleEntity"; | ||
final EntityManager em = emf.createEntityManager(); | ||
try { | ||
em.getTransaction().begin(); | ||
Query q = em.createQuery(jpql); | ||
q.executeUpdate(); | ||
em.getTransaction().commit(); | ||
} finally { | ||
if (em.getTransaction().isActive()) { | ||
em.getTransaction().rollback(); | ||
} | ||
em.close(); | ||
} | ||
} | ||
|
||
} |
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