XMLIDRef behaviour changed from 3.0.3 to 4.0 [message #1857635] |
Fri, 17 February 2023 11:34 |
Michael Wojke 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 #1858849 is a reply to message #1857659] |
Wed, 26 April 2023 11:28 |
Michael Wojke Messages: 6 Registered: February 2023 |
Junior Member |
|
|
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
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.
|
|
|
|
Powered by
FUDForum. Page generated in 0.04548 seconds