This is an automated email from the ASF dual-hosted git repository. pcristof pushed a commit to branch OPENJPA-2939 in repository https://gitbox.apache.org/repos/asf/openjpa.git
commit 397e28d8f9a2b46fa40de91a621c8a7fbb12b16a Author: Paulo Cristovão de Araújo Silva Filho <pcris...@gmail.com> AuthorDate: Sat Jun 28 13:58:52 2025 -0300 [OPENJPA-2939] Fixed handling of UUID in metamodel export and XML/json conversion --- .../openjpa/persistence/jest/JSONObjectFormatter.java | 1 + .../org/apache/openjpa/persistence/jest/XMLFormatter.java | 1 + openjpa-jest/src/test/java/demo/Actor.java | 15 +++++++++++++++ .../org/apache/openjpa/persistence/jest/TestJEST.java | 1 + openjpa-jest/src/test/resources/META-INF/persistence.xml | 7 ++++--- .../openjpa/persistence/meta/AbstractManagedType.java | 4 ++++ 6 files changed, 26 insertions(+), 3 deletions(-) diff --git a/openjpa-jest/src/main/java/org/apache/openjpa/persistence/jest/JSONObjectFormatter.java b/openjpa-jest/src/main/java/org/apache/openjpa/persistence/jest/JSONObjectFormatter.java index 5a50d0ade..681bc35ac 100644 --- a/openjpa-jest/src/main/java/org/apache/openjpa/persistence/jest/JSONObjectFormatter.java +++ b/openjpa-jest/src/main/java/org/apache/openjpa/persistence/jest/JSONObjectFormatter.java @@ -172,6 +172,7 @@ public class JSONObjectFormatter implements ObjectFormatter<JSON> { case JavaTypes.LOCALE: case JavaTypes.STRING: case JavaTypes.ENUM: + case JavaTypes.UUID_OBJ: root.set(fmd.getName(), value); break; diff --git a/openjpa-jest/src/main/java/org/apache/openjpa/persistence/jest/XMLFormatter.java b/openjpa-jest/src/main/java/org/apache/openjpa/persistence/jest/XMLFormatter.java index 6cce9739f..51530f421 100644 --- a/openjpa-jest/src/main/java/org/apache/openjpa/persistence/jest/XMLFormatter.java +++ b/openjpa-jest/src/main/java/org/apache/openjpa/persistence/jest/XMLFormatter.java @@ -287,6 +287,7 @@ public class XMLFormatter implements ObjectFormatter<Document> { case JavaTypes.DATE: case JavaTypes.NUMBER: case JavaTypes.CALENDAR: + case JavaTypes.UUID_OBJ: case JavaTypes.LOCALE: case JavaTypes.STRING: case JavaTypes.ENUM: diff --git a/openjpa-jest/src/test/java/demo/Actor.java b/openjpa-jest/src/test/java/demo/Actor.java index 6a7c3c33d..d104f8b7a 100644 --- a/openjpa-jest/src/test/java/demo/Actor.java +++ b/openjpa-jest/src/test/java/demo/Actor.java @@ -19,15 +19,20 @@ package demo; +import static jakarta.persistence.GenerationType.UUID; + import java.util.Date; import java.util.HashSet; import java.util.Set; +import java.util.UUID; import jakarta.persistence.Entity; import jakarta.persistence.Id; +import jakarta.persistence.GeneratedValue; import jakarta.persistence.OneToMany; import jakarta.persistence.OneToOne; +import org.apache.openjpa.lib.util.UUIDGenerator; import org.apache.openjpa.persistence.FetchAttribute; import org.apache.openjpa.persistence.FetchGroup; import org.apache.openjpa.persistence.FetchGroups; @@ -59,6 +64,8 @@ public class Actor { @OneToMany private Set<Movie> movies; + private UUID randomId; + protected Actor() { } @@ -70,6 +77,7 @@ public class Actor { this.lastName = lastName; this.gender = gender; this.dob = dob; + this.randomId = java.util.UUID.randomUUID(); } public String getId() { @@ -102,6 +110,13 @@ public class Actor { public Set<Movie> getMovies() { return movies; } + public void setRandomId(UUID uuid) { + this.randomId = uuid; + } + + public UUID getRandomId() { + return randomId; + } public void addMovie(Movie movie) { if (movies == null) diff --git a/openjpa-jest/src/test/java/org/apache/openjpa/persistence/jest/TestJEST.java b/openjpa-jest/src/test/java/org/apache/openjpa/persistence/jest/TestJEST.java index 43ba8c4e3..93362d4df 100644 --- a/openjpa-jest/src/test/java/org/apache/openjpa/persistence/jest/TestJEST.java +++ b/openjpa-jest/src/test/java/org/apache/openjpa/persistence/jest/TestJEST.java @@ -38,6 +38,7 @@ import com.meterware.httpunit.WebResponse; import com.meterware.servletunit.ServletRunner; import com.meterware.servletunit.ServletUnitClient; +import demo.DataLoader; import junit.framework.TestCase; /** diff --git a/openjpa-jest/src/test/resources/META-INF/persistence.xml b/openjpa-jest/src/test/resources/META-INF/persistence.xml index 207220cda..3417a1801 100644 --- a/openjpa-jest/src/test/resources/META-INF/persistence.xml +++ b/openjpa-jest/src/test/resources/META-INF/persistence.xml @@ -17,9 +17,10 @@ specific language governing permissions and limitations under the License. --> -<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - version="1.0"> - +<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" + version="2.1"> <persistence-unit name="test-jest"> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AbstractManagedType.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AbstractManagedType.java index f64fd8f71..4246de156 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AbstractManagedType.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AbstractManagedType.java @@ -33,6 +33,7 @@ import java.util.Date; import java.util.HashSet; import java.util.Locale; import java.util.TreeSet; +import java.util.UUID; import jakarta.persistence.metamodel.Attribute; import jakarta.persistence.metamodel.CollectionAttribute; @@ -169,6 +170,9 @@ public abstract class AbstractManagedType<X> extends Types.BaseType<X> case JavaTypes.LOCALE: attrs.add(new Members.SingularAttributeImpl<X, Locale>(this, f)); break; + case JavaTypes.UUID_OBJ: + attrs.add(new Members.SingularAttributeImpl<X, UUID>(this, f)); + break; case JavaTypes.OBJECT: case JavaTypes.OID: case JavaTypes.PC: