Skip to content

[OPENJPA-2937] Merging previously unsaved entity with generated UUID property fixed #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openjpa-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-parent</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<artifactId>openjpa-all</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion openjpa-examples/image-gallery/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-examples</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<groupId>org.apache.openjpa.openjpa-examples</groupId>
Expand Down
2 changes: 1 addition & 1 deletion openjpa-examples/openbooks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-examples</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<groupId>org.apache.openjpa.openjpa-examples</groupId>
Expand Down
2 changes: 1 addition & 1 deletion openjpa-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-parent</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<artifactId>openjpa-examples</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion openjpa-examples/simple/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-examples</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<groupId>org.apache.openjpa.openjpa-examples</groupId>
Expand Down
2 changes: 1 addition & 1 deletion openjpa-features/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-parent</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<artifactId>openjpa-features</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion openjpa-integration/daytrader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-integration</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<artifactId>openjpa-integration-daytrader</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion openjpa-integration/examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-integration</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<artifactId>openjpa-integration-examples</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion openjpa-integration/jmx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-integration</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<artifactId>openjpa-integration-jmx</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion openjpa-integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-parent</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<artifactId>openjpa-integration</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion openjpa-integration/slf4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-integration</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<artifactId>openjpa-integration-slf4j</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion openjpa-integration/tck/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-integration</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<artifactId>openjpa-integration-tck</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion openjpa-integration/validation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-integration</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<artifactId>openjpa-integration-validation</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion openjpa-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-parent</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<artifactId>openjpa-jdbc</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,7 @@ private Object getValue(Object ob, FieldMapping fmd,
case JavaTypes.BIGINTEGER:
case JavaTypes.LOCALE:
case JavaTypes.OBJECT:
case JavaTypes.UUID_OBJ:
case JavaTypes.OID:
return sm.fetchObjectField(i);
default:
Expand Down
2 changes: 1 addition & 1 deletion openjpa-jest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-parent</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<artifactId>openjpa-jest</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion openjpa-junit5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-parent</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<artifactId>openjpa-junit5</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion openjpa-kernel/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-parent</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<artifactId>openjpa-kernel</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ protected boolean attachField(AttachManager manager, Object toAttach,
case JavaTypes.OBJECT:
case JavaTypes.OID:
case JavaTypes.ENUM:
case JavaTypes.UUID_OBJ:
val = fetchObjectField(i);
if (val == null && !nullLoaded)
return false;
Expand Down
2 changes: 1 addition & 1 deletion openjpa-kubernetes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-parent</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<artifactId>openjpa-kubernetes</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion openjpa-lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-parent</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<artifactId>openjpa-lib</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion openjpa-persistence-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-parent</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<artifactId>openjpa-persistence-jdbc</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,69 @@ public void testDefaultValues() {
closeEM(em);
}

public void testMergeBeforePersist() {
EntityManager em = emf.createEntityManager();

UuidGeneratedEntity gv1 = new UuidGeneratedEntity();

em.getTransaction().begin();
gv1 = em.merge(gv1);
em.getTransaction().commit();

em.refresh(gv1);

assertNotNull(gv1.getId());
assertNotNull(gv1.getNativeUuid());
closeEM(em);
}

public void testDetachAndMerge() {
EntityManager em = emf.createEntityManager();
UuidGeneratedEntity gv = new UuidGeneratedEntity();
gv.setBasicUuid(UUID.randomUUID());

em.getTransaction().begin();
em.persist(gv);
em.getTransaction().commit();

assertTrue(em.contains(gv));
em.detach(gv);
em.clear();
assertFalse(em.contains(gv));

Long v = gv.getVersion();
gv.setBasicUuid(UUID.randomUUID());

em.getTransaction().begin();
gv = em.merge(gv);
em.getTransaction().commit();

assertTrue((v + 1) == gv.getVersion());

closeEM(em);
}

public void testGetByReference() {
EntityManager em = emf.createEntityManager();
UuidGeneratedEntity gv = new UuidGeneratedEntity();

em.getTransaction().begin();
em.persist(gv);
em.getTransaction().commit();

assertTrue(em.contains(gv));
em.detach(gv);
UUID id = gv.getId();
UUID nid = gv.getNativeUuid();

em.getTransaction().begin();
UuidGeneratedEntity rgv = em.getReference(UuidGeneratedEntity.class, id);
assertEquals(nid, rgv.getNativeUuid());
em.getTransaction().commit();

closeEM(em);
}

public void testFindByUUIDProperty() {
EntityManager em = emf.createEntityManager();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Version;

@Entity
public class UuidGeneratedEntity {
Expand All @@ -46,6 +47,10 @@ public class UuidGeneratedEntity {

private UUID basicUuid;

@Version
@Column(name = "version_")
private Long version;

@ManyToOne
private UuidGeneratedEntity parent;

Expand Down Expand Up @@ -93,4 +98,12 @@ public void setParent(UuidGeneratedEntity parent) {
this.parent = parent;
}

public Long getVersion() {
return version;
}

public void setVersion(Long version) {
this.version = version;
}

}
2 changes: 1 addition & 1 deletion openjpa-persistence-locking/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-parent</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<artifactId>openjpa-persistence-locking</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion openjpa-persistence/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-parent</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<artifactId>openjpa-persistence</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion openjpa-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-parent</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<artifactId>apache-openjpa</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions openjpa-project/src/doc/manual/manual.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@
]>
<book id="manual">
<bookinfo>
<title>Apache OpenJPA 3.2 User's Guide</title>
<title>Apache OpenJPA 4.1.2-SNAPSHOT User's Guide</title>
<copyright>
<year>2006-2021</year>
<year>2006-2025</year>
<holder>The Apache Software Foundation</holder>
</copyright>
<releaseinfo>Built from OpenJPA version <?eval ${openjpa.version}?> revision <?eval ${buildNumber}?>.</releaseinfo>
Expand Down
2 changes: 1 addition & 1 deletion openjpa-slice/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-parent</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<artifactId>openjpa-slice</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion openjpa-tools/openjpa-fetch-statistics-was/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-tools</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<artifactId>openjpa-fetch-statistics-was</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion openjpa-tools/openjpa-fetch-statistics/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-tools</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<artifactId>openjpa-fetch-statistics</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion openjpa-tools/openjpa-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-tools</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion openjpa-tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-parent</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
<!-- <relativePath>../pom.xml</relativePath>-->
</parent>

Expand Down
2 changes: 1 addition & 1 deletion openjpa-xmlstore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-parent</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<artifactId>openjpa-xmlstore</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion openjpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<parent>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-parent</artifactId>
<version>4.1.1-SNAPSHOT</version>
<version>4.1.2-SNAPSHOT</version>
</parent>

<artifactId>openjpa</artifactId>
Expand Down
Loading
Loading