JavaBeans code generation from XSD

Hi everyone,

I know that this is not a new question, but I still did not find a satisfying answer.

Does anyone know a good code generator for creating JavaBeans out of XSD schemas?

The output of this tool has to comply with the JavaBeans specification, because we want to map these POJOs to a database with the Java Persistence API. Especially lists and sets need to be created correctly, because we will make heavy use of associations.

I've evaluated a large number of tools, most of them are not useable together with JPA. Here is a short list of tools I already tried:

- Castor: Really nice tool, but getter-methods for "java.util.List" objects return a copy of this list as array! Output is not a JavaBean!

- XMLBeans: As far as I've seen, Java objects have to be retrieved via a factory method, I see no possibility to use this library together with JPA. I furthermore doubt that these objects are JavaBeans.

- HyperJaxb2+3: This tool promises to create Java POJOs and Hibernate mappings at the same time. The description looks very good, but the page seems to be down. I was not able to initiate a download for days.

- Altova XMLSpy: This tool allows the generation of Java code out of XSD schemas. But the result is rather ugly. A simple XML "string" is translated into an internal Java class definition instead of a simple "String" instance. I see no usage of these objects together with JPA.

I spent quite a lot of time for searching a good code generation framework that works together with JPA. Has anyone made good experience with any kind of code generators in this area?

Thanks for any help!

Martin

[1687 byte] By [MKostera] at [2007-11-27 6:55:35]
# 1
Use JAXB 2.0
dvohra09a at 2007-7-12 18:32:15 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Hi dvohra09,

thanks for your reply. I think JAXB has the same limitations than XMLBeans. As I read at http://java.sun.com/javaee/5/docs/tutorial/doc/JAXB6.html, object instances shall be only accessed via a factory:

"You should never directly use the generated implementation classes--that is, *Impl.java in the <packagename>/impl directory. These classes are not directly referenceable because the class names in this directory are not standardized by the JAXB specification. The ObjectFactory method is the only portable means to create an instance of a schema-derived interface. There is also an ObjectFactory.newInstance(Class JAXBinterface) method that enables you to create instances of interfaces. "

Did you use JAXB2 together with the Java Persistence API? If yes, can you give me please an example how to map generated classes to the database?

Thanks for your help!

Martin

MKostera at 2007-7-12 18:32:15 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
Factory class is required for JAXB and XMLBeans.
dvohra09a at 2007-7-12 18:32:15 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

Yes, that's exactly what I already said in my previous posts.

Does anyone know a "lightweight" code generator whose output complies with the JavaBeans specification?

I think most code generators are not useable together with ORM tools. Is there anyone who collects experience with persistence frameworks?

Thanks for any help.

Martin

MKostera at 2007-7-12 18:32:15 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5
try beanlet. http://beanlet.sourceforge.net/
jwentinga at 2007-7-12 18:32:15 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6
Oracle TopLink also provides Schema to JavaBean mapping. http://www.oracle.com/technology/products/ias/toplink/doc/11110/relnotes/toplink-relnotes.html
dvohra09a at 2007-7-12 18:32:15 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 7
Oracle TopLink JAXB 1.0 http://www.oracle.com/technology/products/ias/toplink/technical/tips/jaxb/index.htm
dvohra09a at 2007-7-12 18:32:15 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...