users@jaxb.java.net

Re: _at_annotation customization

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Mon, 06 Nov 2006 10:43:01 -0800

Lucas Jordan wrote:
> Is it possible to add annotations to the generated classes by adding
> annotation elements to an xsd file. For example, I would like to add an
> @Entity attribute to each generated class as well as an @Id attribute (plus
> maybe an @GeneratedValue) to selected fields.

Plugin lets you do this kind of things easily.

And if you are specifically looking for persistence annotations, check
out https://hyperjaxb3.dev.java.net/

Also search the archive of this list for the EJB3/JPA and JAXB related
discussions, and in particular updates from Lexi about the status of
hyperjaxb3.


> So, If I have an xsd file that looks something like:
>
> <xsd:element name="Address" type="tns:AddressType"/>
> <xsd:complexType name="AddressType">
> <xsd:sequence>
> <xsd:element name="Id" type="xsd:long"/>
> <xsd:element name="Street" type="xsd:string"/>
> <xsd:element name="City" type="xsd:string"/>
> <xsd:element name="Zip" type="xsd:string"/>
> </xsd:sequence>
> </xsd:complexType>
>
> I would like to have a class like:
>
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlType(name = "AddressType", propOrder = {
> "street",
> "city",
> "zip"
> })
> @Entity()
> public class AddressType implements Serializable{
>
> @XmlElement(name = "SId", namespace = "
> http://xml.netbeans.org/schema/Types", required = true)
> @Id @GeneratedValue long id;
> @XmlElement(name = "Street", namespace = "
> http://xml.netbeans.org/schema/Types", required = true)
> protected String street;
>
>
> ..
> }
>
> thanks!
> -Lucas
>
> P.S. Currently I am hand editing each class by adding the annotations, this
> works, but makes development a pain, since I have to remember which classes
> are annotated how when ever I rebuild the classes.
> P.P.S Obviously I am trying use the generated class with the Java
> Persistence API, If anyone has a good solution to this, I would love to hear
>


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com