-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Will Dazey <dazeydev.3@gmail.com>
- Loading branch information
Showing
2 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
...test.jse/src/it/java/org/eclipse/persistence/jpa/test/collection/TestBasicCollection.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,87 @@ | ||
/* | ||
* Copyright (c) 2023 IBM Corporation. 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: | ||
package org.eclipse.persistence.jpa.test.collection; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.EntityManagerFactory; | ||
import jakarta.persistence.Query; | ||
|
||
import java.util.Set; | ||
|
||
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.framework.Property; | ||
import org.eclipse.persistence.jpa.test.collection.model.CityEntity; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(EmfRunner.class) | ||
public class TestBasicCollection { | ||
|
||
@Emf(createTables = DDLGen.DROP_CREATE, | ||
classes = { CityEntity.class }, | ||
properties = { @Property(name = "eclipselink.logging.level", value = "ALL"), | ||
@Property(name = "eclipselink.logging.level.sql", value = "FINE"), | ||
@Property(name = "eclipselink.logging.parameters", value = "true")}) | ||
private EntityManagerFactory emf; | ||
|
||
@Test | ||
public void testUpdateBasicCollectionWithQuery() { | ||
EntityManager em = emf.createEntityManager(); | ||
try { | ||
em.getTransaction().begin(); | ||
em.persist(new CityEntity("Minneapolis", Set.of(608))); | ||
em.getTransaction().commit(); | ||
} finally { | ||
if (em.getTransaction().isActive()) { | ||
em.getTransaction().rollback(); | ||
} | ||
if(em.isOpen()) { | ||
em.close(); | ||
} | ||
} | ||
|
||
em = emf.createEntityManager(); | ||
try { | ||
em.getTransaction().begin(); | ||
Query q = em.createQuery("UPDATE City o SET o.areaCodes=?1 WHERE o.name=?2"); | ||
q.setParameter(1, Set.of(563)); | ||
q.setParameter(2, "Minneapolis"); | ||
q.executeUpdate(); | ||
em.getTransaction().commit(); | ||
} finally { | ||
if (em.getTransaction().isActive()) { | ||
em.getTransaction().rollback(); | ||
} | ||
if(em.isOpen()) { | ||
em.close(); | ||
} | ||
} | ||
|
||
em = emf.createEntityManager(); | ||
try { | ||
em.getTransaction().begin(); | ||
CityEntity find2 = em.find(CityEntity.class, "Minneapolis"); | ||
em.getTransaction().commit(); | ||
} finally { | ||
if (em.getTransaction().isActive()) { | ||
em.getTransaction().rollback(); | ||
} | ||
if(em.isOpen()) { | ||
em.close(); | ||
} | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...pa.test.jse/src/it/java/org/eclipse/persistence/jpa/test/collection/model/CityEntity.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,39 @@ | ||
/* | ||
* Copyright (c) 2023 IBM Corporation. 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: | ||
package org.eclipse.persistence.jpa.test.collection.model; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
import jakarta.persistence.CollectionTable; | ||
import jakarta.persistence.ElementCollection; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
|
||
@Entity | ||
public class CityEntity { | ||
|
||
@Id | ||
public String name; | ||
|
||
public Set<Integer> areaCodes; | ||
|
||
public CityEntity() {} | ||
|
||
public CityEntity(String name, Set<Integer> areaCodes) { | ||
this.name = name; | ||
this.areaCodes = areaCodes; | ||
} | ||
} |