users@jaxb.java.net

Is there a way to mark up my xsd files so that xjc will generate java classes with hibernate annotations?

From: Andy Davidson <andy_davidson_at_apple.com>
Date: Fri, 21 Jan 2011 16:41:15 -0800

Hi

Is there a way to mark up my xsd files so that xjc will generate java classes with hibernate annotations? Worst comes to worst, the hybernate mapping can be specified in an xml file. The advantage of adding <appinfo> to the xsd files is that xsd file changes will trigger java compiler errors. This is should be faster and easier to track down.

for example

<annotation>
        <appinfo>
                <jaxb:decorate>@Entity</jaxb:decorate>
                <jaxb:decorate>@Table(name = "employee")</jaxb:decorate>
    </appinfo>
</annotation>
<complexType name="Employee">
        <sequence>
                < annotation >
                        <appinfo>
                                <jaxb:decorate>@Id</jaxb:decorate>
                                <jaxb:decorate>@Entity</jaxb:decorate>
                        <appinfo>
                </annotation>
                <element name="id" type="integer"/>

                <annotation>
                        <appinfo>
                                <jaxb:decorate>@Column(name = "name")</jaxb:decorate>
                        <appinfo>
                </annotation>
                <element name="name" type="string" />


        <sequence>
</complexType>



inaddition to the jaxb annontation, xjc would add the extra hybernate annontations

@Entity
@Table(name = "employee")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Employee", propOrder = {
    "id",
    "name"
})
public class Employee implements Serializable {
  public Employee() {

  }
  @Id
  @Column(name = "id")
  Integer id;

  @Column(name = "name")
  String name;

  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;
  }

}

thanks

Andy