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.