Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » XMLIDRef behaviour changed from 3.0.3 to 4.0(XmlID_Annotation is no longer respected from superclasses)
XMLIDRef behaviour changed from 3.0.3 to 4.0 [message #1857635] Fri, 17 February 2023 11:34 Go to next message
Michael Wojke is currently offline Michael WojkeFriend
Messages: 6
Registered: February 2023
Junior Member
Hello there,

first, excuse my english :-)

In our application, we make extensive use of inheritance. Any class that is written to the database or to an xml file is (over several steps) extending one base class, which carries the id property annotated with @XmlId.

up to 3.03, any reference to a sub(sub-sub-...) class of this could be annotated with @XMLIdRef.

Since 4.0.0 we get an error::
org.eclipse.persistence.exceptions.JAXBException:
Exception Description: Invalid XmlIDREF on property [targetFieldPosition]. Class [de.gtt.configDB.GttFieldPosition] is required to have a property annotated with XmlID.
at org.eclipse.persistence.exceptions.JAXBException.invalidIdRef(JAXBException.java:207) ~[eclipselink-4.0.1-RC1.jar:4.0.1-RC1]
at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.finalizeProperty(AnnotationsProcessor.java:1103) ~[eclipselink-4.0.1-RC1.jar:4.0.1-RC1]
at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.finalizeProperties(AnnotationsProcessor.java:992) ~[eclipselink-4.0.1-RC1.jar:4.0.1-RC1]
at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.processClassesAndProperties(AnnotationsProcessor.java:309) ~[eclipselink-4.0.1-RC1.jar:4.0.1-RC1]
at org.eclipse.persistence.jaxb.compiler.Generator.<init>(Generator.java:154) ~[eclipselink-4.0.1-RC1.jar:4.0.1-RC1]

(just tried with the latest RC).

The problem seems to be in this code:
private void finalizeProperty(Property property, TypeInfo targetInfo, JavaClass typeClass, JavaClass jClass){
        if (targetInfo != null && targetInfo.isTransient() && property.getXmlElements() == null) {
            property.setTransientType(true);
        }

        // validate XmlIDREF
        if (property.isXmlIdRef()) {
            // the target class must have an associated TypeInfo unless
            // it is Object
            if (targetInfo == null && !typeClass.getQualifiedName().equals(JAVA_LANG_OBJECT)) {
                throw JAXBException.invalidIDREFClass(jClass.getQualifiedName(), property.getPropertyName(), typeClass.getQualifiedName());
            }
            // if the property is an XmlIDREF, the target must have an
            // XmlID set
            if (targetInfo != null && targetInfo.getIDProperty() == null && !preCheckXmlID(typeClass, targetInfo)) {
                throw JAXBException.invalidIdRef(property.getPropertyName(), typeClass.getQualifiedName());
            }
        }


It check only the direct superclass, (preCheckXmlID) not the entire Inheritance tree.

Is this a bug? Or a feature :-) Or are we missing something?
Re: XMLIDRef behaviour changed from 3.0.3 to 4.0 [message #1857659 is a reply to message #1857635] Sun, 19 February 2023 19:34 Go to previous messageGo to next message
Radek Felcman is currently offline Radek FelcmanFriend
Messages: 20
Registered: March 2021
Junior Member
Hello,

it should be related with
https://github.com/eclipse-ee4j/eclipselink/pull/235
https://github.com/eclipse-ee4j/eclipselink/commit/215630a092476a66804f08cfc3a4e3d4c71d3cb5
But this change is there from 3.0.0-M1 I mean included in final versions 3.0.0 and higher.
Could You please provide some code example based on Your entities with
@XmlIDREF
and
@XmlID
or check test case in mentioned PR
package org.eclipse.persistence.testing.jaxb.annotations.xmlidref.inheritance
.

Thank You
Radek Felcman
Re: XMLIDRef behaviour changed from 3.0.3 to 4.0 [message #1858849 is a reply to message #1857659] Wed, 26 April 2023 11:28 Go to previous messageGo to next message
Michael Wojke is currently offline Michael WojkeFriend
Messages: 6
Registered: February 2023
Junior Member
index.php/fa/43149/0/Just tried out 4.0.1, problem still there.

Here re the code snippets you asked for:

First the inheritance tree of our classe:

GttUnverwsionedCOnfig contains the XMLID, GttFieldPosition is referenced as XMLIDRef
index.php/fa/43149/0/

The id Property in GtttUnversionedConfig:
@Id
	@GeneratedValue(generator=GttSequence.SEQUENCE_NAME)
	@Column(nullable = false, precision = 12)
	@XmlElement(required=true)
	@XmlID
	@XmlJavaTypeAdapter(IdToStringAdapter.class)
	private Long id;


The IdToStringAdapter (sorry, comments are in german):

/**
 * <p>Ziel der Klasse: Konvertiert einen Long zu einem String und umgekehrt.</p>
 * Notwendig, um XmlID an einem Long zu annotieren.
 * 
 * <pre>
 * @author  GTT Gesellschaft für Technologie Transfer (c) 2010
 * @version @(#) $Revision: 1.1 $ $Author: mas $ $Date: 11.11.2010 $
 * 
 *  Datum:		Bearbeiter:	Änderungen:
 *  24.11.2010	Schumann	neu erstellt
 * </pre>
 */
public class IdToStringAdapter extends XmlAdapter<String, Long> {
	
	/**
	 * Konvertiert von Xml zu einem Objekt bzw. einer Liste von Objekten.
	 * @param value String zu einem Long
	 * @return Long
	 */
	@Override
	public Long unmarshal(String value) throws Exception {
		return Long.parseLong(value);
	}

	/**
	 * @param value Long zu einem String
	 * @return String
	 */
	@Override
	public String marshal(Long value) throws Exception {
		return String.valueOf(value);
	}
}


The reference (one example, there are multiple usages)
/**
	 * Dieses Property definiert die FieldPosition, die als Ziel für die
	 * Follower-FieldPosition verwendet werden soll. Oft bezieht sich die
	 * Follower-FieldPosition auf den Primär-Schlüssel des Nachfolgers,
	 * dementsprechent stellt diese FieldPosition den Primärschlüssel des
	 * Nachfolgers da. Dies ist nur ein Beispiel und die Follower- sowie
	 * die FollowerTarget-FieldPosition können frei auf jede beliebige
	 * Spalte einer Tabelle gelegt werden. Darf  <code>null</code> sein.
	 */
	@OneToOne(optional=true)
	@XmlIDREF
	private GttFieldPosition targetFieldPosition;


Everything ist fine in 3.0.3, in 4.x we get the error mentioned.
Re: XMLIDRef behaviour changed from 3.0.3 to 4.0 [message #1859542 is a reply to message #1858849] Wed, 14 June 2023 09:19 Go to previous message
Michael Wojke is currently offline Michael WojkeFriend
Messages: 6
Registered: February 2023
Junior Member
Problem still there in 4.0.2-RC1.

Anyone out there with the sam problem or - even better - a solution?
Previous Topic:Eclipselink 3.0.3 an Java 20
Next Topic:EL 3.0.x not writing into DiscriminatorColumn after migration from 2.7.3
Goto Forum:
  


Current Time: Mon Apr 29 13:36:13 GMT 2024

Powered by FUDForum. Page generated in 0.04607 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top