@XmlAccessor setting

8 views
Skip to first unread message

ggran...@gmail.com

unread,
Feb 13, 2017, 9:23:14 PM2/13/17
to minuteproject
Hi Florian,

When xml annotation is enabled entities are decorated with @XmlAccessor annotation like this:

@XmlAccessorType(XmlAccessType.FIELD)

This doesn't seem appropriate to me.  The XmlAccessType.FIELD selection behaves as documented:

    /**
     * Every non static, non transient field in a JAXB-bound class will be automatically
     * bound to XML, unless annotated by {@link XmlTransient}.
     *
     * Getter/setter pairs are bound to XML only when they are explicitly annotated
     * by some of the JAXB annotations.
     */

This setting will include all fields - even the ones that are not annotated.   If you are explicitly annotating the fields you want then this setting seems more approprieate:

@XmlAccessorType(XmlAccessType.NONE)

documented as:

    /**
     * None of the fields or properties is bound to XML unless they
     * are specifically  annotated with some of the JAXB annotations.
     */

Also, I noticed that one of the fields output by JPA2 is missing the annotation:

    @ManyToOne (fetch=FetchType.LAZY , optional=false)                //   <<--------NOTE: missing xml annotation
    @JoinColumn(name="EotcSystemId", referencedColumnName = "EotcSystemId" , nullable=false , unique=false , insertable=true, updatable=true) 
    private EotcSystem eotcSystemId;  

    @XmlElement (name="eotcSystemId")
    @Column(name="EotcSystemId"  , nullable=false , unique=false, insertable=false, updatable=false)
    private Integer eotcSystemId_;

To fix this I added to DomainEntityJPA2Annotation.vm locally at line:

211:
    @ManyToOne (fetch=FetchType.$fetchType #if ($isMandatory && !$table.isLinkEntity()), optional=false#end)
    @JoinColumn(name="$localColumnName", referencedColumnName = "$reference.foreignColumnName" #if($localColumn.isRequired()), nullable=false#else, nullable=true#end #if($isColumnUnique), unique=true #else, unique=false#end $insertableUpdatableRelationship) 
#exposeRelationship($table, $reference)
#set($colVar = $commonUtils.getColumnAliasVariable($table, $reference))
#if($addXmlBinding)
    @XmlElement (name="${colVar}Ref")
#end
    $accessor $linkedTableClass ${colVar};  

Note the addition of "Ref" at the end of xml annotation name.  I did this because when I took the WSDL generated from these annotation to a code generation tool on the client side, the names generated that only differed by and "_" (underscore) would end up colliding because the code generation would simply remove underbars.


Florian Adler

unread,
Feb 23, 2017, 10:41:56 AM2/23/17
to minute...@googlegroups.com
Hello Greg,

Thanks very much for those feedbacks, feel free to adapt the velocity template to suit your needs.
In the case of xml, I have just done experimental works and I do not use it at the moment, so I will take your modification for granted. If you can send me the last version of DomainEntityJPA2Annotation.vm so that I can merge it and check the compatibility with the standard (without xml) generation.

Best regards,

Florian.

--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "minuteproject".
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse minuteproject+unsubscribe@googlegroups.com.
Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.

ggran...@gmail.com

unread,
Feb 27, 2017, 7:22:41 PM2/27/17
to minuteproject
Hi Florian,

Please find attached my version of DomainEntityJPA2Annotation.vm
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse minuteprojec...@googlegroups.com.
DomainEntityJPA2Annotation.vm
Reply all
Reply to author
Forward
0 new messages