This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 228733 - Entity Classes whith JAXB Annotations does not generate @XmlType annotation with propOrder parameter to order fields
Summary: Entity Classes whith JAXB Annotations does not generate @XmlType annotation w...
Status: RESOLVED WONTFIX
Alias: None
Product: javaee
Classification: Unclassified
Component: Persistence (show other bugs)
Version: 7.3
Hardware: PC Linux
: P3 normal (vote)
Assignee: Sergey Petrov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-19 00:15 UTC by talesmetal
Modified: 2016-07-07 08:55 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description talesmetal 2013-04-19 00:15:38 UTC
When I generate an entity class from database and Generate JAXB Annotations is active, then I do not get @XmlType annotation with the propOrder parameter, this annotation is very important when you deploy you EJB to Glassfish, because when the wsdl and xsd files are generated with wsgen you get the complex type definition in xsd file all the elements are in alphabetical order then you lose all the sense of the constructors when you generate your classes from wsdl file.

I don't know if I can configure NetBeans to indicate that I want the @XmlType Annotation with the propOrder parameter

Example

By now NetBeans creates this class

----------------------------------------------
Java Entity Class from Database

@Entity
@Table(name = "employee")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Employee.findAll", query = "SELECT e FROM Employee e")})
public class Employee implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id", nullable = false)
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 90)
    @Column(name = "name", nullable = false, length = 90)
    private String name;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 90)
    @Column(name = "lastName", nullable = false, length = 90)
    private String lastName;
    @Basic(optional = false)
    @NotNull
    @Column(name = "birthdate", nullable = false)
    @Temporal(TemporalType.DATE)
    private Date birthdate;

    public Employee() {
    }

    public Employee(Integer id) {
        this.id = id;
    }

    public Employee(Integer id, String name, String lastName, Date birthdate) {
        this.id = id;
        this.name = name;
        this.lastName = lastName;
        this.birthdate = birthdate;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public Date getBirthdate() {
        return birthdate;
    }

    public void setBirthdate(Date birthdate) {
        this.birthdate = birthdate;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Employee)) {
            return false;
        }
        Employee other = (Employee) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "jpa.Employee[ id=" + id + " ]";
    }
    
}


XSD Segment of tht File Generated with wsgen (Glassfish)

<xs:complexType name="employee">
<xs:sequence>
<xs:element name="birthdate" type="xs:dateTime" minOccurs="0"/>
<xs:element name="id" type="xs:int" minOccurs="0"/>
<xs:element name="lastName" type="xs:string" minOccurs="0"/>
<xs:element name="name" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>

--------------------------------------------------------------

If you see the elements are ordered alphabetically

... and I need to have this extra line after @XmlRootElement

@XmlType(propOrder={"id", "name", "lastName", "birthdate"})

in order to get this xsd segment

------------------------------------------------------------
<xs:complexType name="employee">
<xs:sequence>
<xs:element name="id" type="xs:int" minOccurs="0"/>
<xs:element name="name" type="xs:string" minOccurs="0"/>
<xs:element name="lastName" type="xs:string" minOccurs="0"/>
<xs:element name="birthdate" type="xs:dateTime" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
-----------------------------------------------------------

This segment is ordered in the same order as the database table columns


Thanks for your help
Comment 1 Petr Jiricka 2013-04-22 11:23:30 UTC
This can be considered either a JPA issue or a JAX-WS issue. Sergey, can you please investigate?
Comment 2 Sergey Petrov 2013-04-22 12:28:16 UTC
ok, persistence wizard and persistence category.
but I don't see it as p1, at most p2, as manual correction for generated code is required but it's trivial.

I remember there was some similar complain before regarding columns ordering but I don't remember exactly and may be it was something withing eclipse. Also I got name ordering was default in hibernate 3.2.1 for jpa.

But fix may be easy and I can try to look later this week.
Comment 3 Sergey Petrov 2013-06-28 13:35:29 UTC
This code is generated in JavaPersistenceGenerator, and it's under persistence category.
Also I found http://stackoverflow.com/questions/5435138/jaxb-and-property-ordering to get some ideas.
It seems "undefined" behavior may be jaxb provider specific, may depend on jdk etc. Initially entity generator wasn't implemented to follow specific order, in my opinion it's more like enhancement request rather then issue. Also fields order may not match table columns order correctly at least fist out for simple fields and last or relations. I afraid implementation may introduce some issues when propOrder may fail to list all required fields or list something wrong,  I would prefer to keep current limited annotations autogenerated.
Comment 4 Sergey Petrov 2013-06-28 18:36:43 UTC
There is no statement what order is expected in first comment, I assume it may be configurable like alphabetical, as in code, as in table, undefined. 
Currently its likely undefined an match alphabetical within wsgen.
Comment 5 Martin Balin 2016-07-07 08:55:45 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss