Skip to content

Commit

Permalink
Issue eclipse-ee4j#1727 - Added test case.
Browse files Browse the repository at this point in the history
Signed-off-by: Tomáš Kraus <tomas.kraus@oracle.com>
  • Loading branch information
Tomas-Kraus committed Oct 11, 2022
1 parent 140718f commit 944b4f4
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 4 deletions.
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();
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018 IBM Corporation. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -24,7 +24,7 @@
public class SimpleEntity {

@Id @Column(name="KEY_CHAR")
private String KeyString;
private String keyString;

@Column(name="ITEM_STRING1")
private String itemString1;
Expand All @@ -44,12 +44,33 @@ public class SimpleEntity {
@Column(name="ITEM_INTEGER2")
private int itemInteger2;

public SimpleEntity() {
keyString = null;
itemString1 = null;
itemString2 = null;
itemString3 = null;
itemString4 = null;
itemInteger1 = null;
itemInteger2 = -1;
}

public SimpleEntity(String keyString, String itemString1, String itemString2,
String itemString3, String itemString4, Integer itemInteger1, int itemInteger2) {
this.keyString = keyString;
this.itemString1 = itemString1;
this.itemString2 = itemString2;
this.itemString3 = itemString3;
this.itemString4 = itemString4;
this.itemInteger1 = itemInteger1;
this.itemInteger2 = itemInteger2;
}

public String getKeyString() {
return KeyString;
return keyString;
}

public void setKeyString(String keyString) {
KeyString = keyString;
this.keyString = keyString;
}

public String getItemString1() {
Expand Down

0 comments on commit 944b4f4

Please sign in to comment.