Preventing NetBeans JAXB Submissions

I'm developing a SOAP service using JAX-WS and JAXB under NetBeans 6.8, and I'm a little frustrated that Netbeans wastes my work every time the XSD schema binds JAXB to a change.

To develop, the IDE automatically generates schema-bound classes which can then be (un) ordered from / to XML using JAXB. To these classes, I added additional methods (for example) to convert to separate classes for saving to a database with JPA. The problem is that whenever the schema changes and I rebuild, these classes are restored and all my own methods are removed. I can replace them manually by copying them from a backup file, but this is quite time consuming and tedious. Since I use an iterative design approach, the schema changes quite often, and I spend a lot of time when it does just to re-create my previous code.

While an IDE that automatically regenerates JAXB-related classes is perfectly reasonable and I don't want to imply otherwise, I was wondering if anyone has any bright ideas on how to prevent my extra work from having to manually regenerate has my schema changed every time?

+2


a source to share


2 answers


Making changes to the XJC generation source is not really a good idea for the reasons you discovered. You must either use the binding setup or XJC for the plugin to generate the extra code you need, or you can pull your extra code out of the XJC generation code and into separate source files.

If your additional code is intended to convert between the JAXB and JPA classes, it can probably stand on its own as a separate translation layer. It's not very OO, but it will get around your problem.



Also, there is an XJC plugin that should let you save code that was manually added to the generated source, but it's poorly documented (and I haven't used it myself). You may need to chat at http://jaxb.dev.java.net/ to learn how to use it.

+1


a source


Instead of modifying the generated classes to add methods, extend the generated classes and add additional methods to your classes derived from the generated classes.



0


a source







All Articles