JPA : Support Hibernate XML Mappings

Bug #656847 reported by bouil on 2010-10-08
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Querydsl
Fix Released
Medium
Unassigned

Bug Description

Would be nice if Querydsl could support also hibernate xml configuration (hbm.xml)

Revision history for this message
Timo Westkämper (timo-westkamper) wrote :

I assume you mean to make the code generation use hibernate XML configuration as the basis for the domain model instead of using APT?

Revision history for this message
bouil (bouil) wrote :

Yes, it was exactly what I mean. Thanks for the reformulation :-)

Changed in querydsl:
importance: Undecided → Medium
status: New → In Progress
summary: - Support Hibernate XML Mappings
+ JPA : Support Hibernate XML Mappings
Revision history for this message
Timo Westkämper (timo-westkamper) wrote :

HibernateDomainExporter provides now the functionality you requested :

        File configuration = new File("examples.hbm.xml");
        HibernateDomainExporter exporter = new HibernateDomainExporter(
          "Q", // name prefix
          new File("target/gen3"), // target folder
          configuration); // hbm files (varargs)

          exporter.export();

Changed in querydsl:
status: In Progress → Fix Committed
Revision history for this message
bouil (bouil) wrote :

Who, I'm impressed how fast you implements this functionality. I can now give to the project a try in a wider context.

I had a quick look on the querydsl-jpa/src/main/java/com/mysema/query/jpa/hibernate/HibernateDomainExporter.java file and just got a bit suprised you parsed the XML file instead of trying to work with org.hibernate.cfg.Configuration directly. But maybe it is easier that way.

Is there a maven plugin that can integrate the HibernateDomainExporter ? If not I could simply use the groovy-maven-plugin to execute the previous code in the correct build phase.

Revision history for this message
Timo Westkämper (timo-westkamper) wrote :

I took the XML approach, since I could easily generate dummy hbm xml files for testing. Using the Hibernate Tools to generate hbm xml files from annotated classes didn't work.

> Is there a maven plugin that can integrate the HibernateDomainExporter ?

No. Using the groovy-maven-plugin sounds good.

Revision history for this message
Timo Westkämper (timo-westkamper) wrote :

I will see how easily I can refactor the HibernateDomainExporter to use the Hibernate configuration.

Revision history for this message
Timo Westkämper (timo-westkamper) wrote :

Refactored to work with Hibernate configuration :

  HibernateDomainExporter provides now the functionality you requested :
  File configuration = new File("examples.hbm.xml");
  HibernateDomainExporter exporter = new HibernateDomainExporter(
    "Q", // name prefix
    new File("target/gen3"), // target folder
    configuration); // instance of org.hibernate.cfg.Configuration

  exporter.export();

This was actually easier. But the implementation still relies on reflection.

Revision history for this message
Timo Westkämper (timo-westkamper) wrote :

Released in 2.0.2

Changed in querydsl:
status: Fix Committed → Fix Released
Revision history for this message
bouil (bouil) wrote :

I believe there is a small error in the documentation of this item. You kept the

 File configuration = new File("examples.hbm.xml");

but in fact, the "configuration" variable should be a org.hibernate.cfg.Configuration object.

Btw, thanks for making a release with that feature.

Revision history for this message
Timo Westkämper (timo-westkamper) wrote :

Thanks, I just fixed the docs.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers