2

I understand that the Hyperjaxb3 library will be quite useful for my project, read a couple of descriptions across multiple sites, and decided to embed it into my Spring-Hibernate project.

I have found a reference to Hyperjaxb3 in https://jaxb.java.net/, which looks pretty official, but the hyperlink - http://confluence.highsource.org/display/HJ3/Home - doesn't open.

I have found some old POM examples, included it into my project, and located some of the old versions references, tried to eliminate them, but right now it seems that I am bumping into a dependency on an old Hibernate version, the error is like this:

java.util.ServiceConfigurationError: com.sun.tools.xjc.Plugin: Provider org.jvnet.hyperjaxb3.hibernate.plugin.HibernatePlugin could not be instantiated: java.lang.NoClassDefFoundError: org/hibernate/type/MutableType

I am wondering if there is better Maven entry, if the project is alive and how do I use it with moder Hibernate.

This is my pom excerpt about Hyperjaxb3, where I exclude some outdated links and specify the latest versions of other dependencies:

    <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-core</artifactId>
        <version>${jaxb-version}</version>
    </dependency>        
    <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-xjc</artifactId>
        <version>${jaxb-version}</version>
    </dependency>  
    <!--<dependency>
        <groupId>org.jvnet.hyperjaxb3</groupId>
        <artifactId>hyperjaxb3</artifactId>
        <version>0.6.1</version>
    </dependency>        -->
    <dependency>
        <groupId>org.jvnet.hyperjaxb3</groupId>
        <artifactId>hyperjaxb3-hibernate-plugin</artifactId>
        <version>0.1</version>
        <exclusions>
            <exclusion>
                <groupId>hsqldb</groupId>
                <artifactId>hsqldb</artifactId>
            </exclusion>
            <exclusion>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
            </exclusion>
            <exclusion>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
            </exclusion>
            <exclusion>
                <groupId>net.sf.saxon</groupId>
                <artifactId>saxon</artifactId>
            </exclusion>
            <exclusion>
                <groupId>net.sf.saxon</groupId>
                <artifactId>saxon-dom</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.xml.bind</groupId>
                <artifactId>jaxb-xjc</artifactId>
            </exclusion>
        </exclusions>
    </dependency>  
    <dependency>
        <groupId>asm</groupId>
        <artifactId>asm</artifactId>
        <version>3.3.1</version>
    </dependency>
    <dependency>
        <groupId>asm</groupId>
        <artifactId>asm-attrs</artifactId>
        <version>2.2.3</version>
    </dependency>
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>3.2.1</version>
    </dependency>

    <dependency>
        <groupId>commons-beanutils</groupId>   
        <artifactId>commons-beanutils</artifactId>
        <version>1.9.2</version>
    </dependency>
    <dependency>
        <groupId>commons-lang</groupId>   
        <artifactId>commons-lang</artifactId>
        <version>2.6</version>
    </dependency>
    <dependency>
        <groupId>commons-logging</groupId>   
        <artifactId>commons-logging</artifactId>
        <version>1.2</version>
    </dependency>

I am not currently trying to generate annotated Hibernate entity classes, but POJOs from the PurchaseOdrer example. This is what I currently do:

public void initializeModel(String name, InputStream src, String dir) throws IOException, URISyntaxException{
    dir = Paths.get(new URL(dir).toURI()).toString();
    File directory = new File(dir);
    directory.mkdirs();

    SchemaCompiler sc = XJC.createSchemaCompiler();
    sc.setDefaultPackageName(this.getClass().getPackage().getName() + ".generated");

    InputSource is = new InputSource(src);
    is.setSystemId(name);

    sc.parseSchema(is);
    S2JJAXBModel model = sc.bind();
    JCodeModel codeModel = model.generateCode(null, null);

    CodeWriter cw = new FileCodeWriter(directory);        
    codeModel.build(cw);
}
fedd
  • 880
  • 12
  • 39

1 Answers1

5

Disclaimer: I'm the author of Hyperjaxb3.

The project is hosted on GitHub:

The latest version 0.6.1 is functional, works as it should.

However, I don't develop it actively anymore.

Will it work with the current version of hibernate?

Version 0.6.1 works was tested with Hibernate 4.1.7. HJ3 is just a code generator which produces standard JPA-annotated classes. So chances are pretty good that it will work with latest versions of Hibernate.

I just can't get the 0.6.1 jar from Maven. Seems like it was eliminated from maven repositories.

Really? Still there.

http://repo1.maven.org/maven2/org/jvnet/hyperjaxb3/hyperjaxb3-ejb-plugin/0.6.1/

An I don't understand if I need the "hyperjaxb3-hibernate-plugin" 0.1 from the year 2011.

You definitely don't.

Or do you aware of any fork or an analog?

Unfortunately, nothing comes close.

lexicore
  • 42,748
  • 17
  • 132
  • 221
  • Thanks! A couple of questions, sorry. Will it work with the current version of hibernate? – fedd Mar 14 '16 at 15:00
  • it's interesting. I just can't get the 0.6.1 jar from Maven. Seems like it was eliminated from maven repositories. An I don't understand if I need the "hyperjaxb3-hibernate-plugin" 0.1 from the year 2011. Or do you aware of any fork or an analog? Thanks! – fedd Mar 14 '16 at 16:07
  • Thanks again, is there an example how one can generate the jpa code from xsd file(s) in a plain spring webmvc app? I failed to find any online. – fedd Mar 14 '16 at 21:51
  • I see this http://gerardnico.com/wiki/language/java/hyperjaxb but I mean programmatically, without maven, ant etc, as shown in my question. I understand, I have to specify some Plugin in generateCode method call - but which one? – fedd Mar 15 '16 at 13:14
  • @fedd You don't generate code in a plain Sping WebMVC app. Code generation is a build process step. Well, you can do it in the runtime (and compile it afterwards as well) but this starts all the possible alarms for me. – lexicore Mar 15 '16 at 13:23
  • I am already generating the code during runtime with Jaxb, I will be grateful if you hint me on how to do the same making the generated code to be JPA entity definitions. (I will find out how to compile and load the classes by myself) – fedd Mar 15 '16 at 14:01
  • @fedd Here's an old piece of code which might be helpful: https://github.com/highsource/hyperjaxb3/blob/master/misc/dynamic/src/main/java/org/jvnet/hyperjaxb3/ejb/dynamic/DynamicCompiler.java – lexicore Mar 15 '16 at 15:10
  • thanks, I am already meditating over it for a couple of hours... but it doesn't seem to use anything from hyperjaxb3. Can't see where it creates a JPA-compatible code – fedd Mar 15 '16 at 15:15
  • See [these lines](https://github.com/highsource/hyperjaxb3/blob/master/misc/dynamic/src/main/java/org/jvnet/hyperjaxb3/ejb/dynamic/DynamicCompiler.java#L122-L123) where the HJ3 plugin is enabled. Anyway, this is far over your original question. – lexicore Mar 15 '16 at 21:14
  • 1
    @lexicore Does documentation like what used to be at http://confluence.highsource.org/display/HJ3/Home still exist anywhere? – Appak Aug 11 '16 at 16:47
  • @lexicore - I am also interested in replica of confluence from highsource.org site, is it anywhere to get? – kensai Aug 29 '17 at 10:20
  • I'll try to start that old server again but I have no idea how to secure Confluence content. – lexicore Aug 29 '17 at 11:50