Book a Demo

Author Topic: Generating Hibernate Mappings  (Read 5192 times)

Owl Saver

  • EA User
  • **
  • Posts: 37
  • Karma: +0/-0
  • Never give up.
    • View Profile
Generating Hibernate Mappings
« on: February 06, 2007, 06:48:30 am »
My first cut at database integration was:
- Create a domain model
- Transform the model to Java and DDL models
- Generate Java from one and DDL from the other

However, this ran into two issues. First, there are limits in EA regarding multiple relationships and types of relationships for DDL generation.

More importantly, I would have to hand code the Java to Database code. So, I looked into it and found Hibernate as a mature ORM solution.

Since EA does not generate Hibernate Mappings I would like to give it a try. Here are my questions:

I have seen a number of discussions about this in the forums. Have they all been abandoned? Is it harder than it looks?

I am thinking that one Java model with Tags should support both Java and Hibernate. Does this make sense? Do I really need to treat Hibernate as a separate language and model?

Is there a way to dump the complete Java Code template so I can modify it to support Hibernate? The Export in Tools/Export Reference Data... does not include the Java template.

Thanks for your help.

beaf

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Generating Hibernate Mappings
« Reply #1 on: February 07, 2007, 08:27:53 am »
I'm not sure if it especially complicated, but it will be quite a big job. As you say, you have to create the Java, the DDL, and the Hibernate mapping files (hbm.xml).

There are tools within Hibernate that generate the Java and DDL from the Hibernate mapping files. Similarly, you can use XDoclet to generate the Hibernate mapping files from the Java, and then in turn generate the DDL from the Hibernate mapping files.

The next issue you have is keeping the Java and DDL in sync in EA if you use EA to generate the Java and DDL. I've found the Model Transformation generators struggle with many-to-many relationships, particularly those from associative objects, which seems to form quite large parts of my models owing to vague requirements for understanding the relationship between classes. ???

I found quite a quick way was to modify the EA Java code generators to add XDoc comments into the headers, and then use XDoclet to do the hard work of creating the hbm.xml files. However, I abandoned its widescale use because it repeated the comments for both the get and set methods, which resulted in two column entries for each attribute. I now have a Perl script that generates the Java, DDL, and hbm.xml files. It is still a pain to create the Perl-based configuration files from the design, but the process is much faster than generating all by hand.

Saying that, if someone does do a proper job for creating the transforms, they'll have me as a customer! If I can help with some of the concepts, don't hesitate to contact me.

Owl Saver

  • EA User
  • **
  • Posts: 37
  • Karma: +0/-0
  • Never give up.
    • View Profile
Re: Generating Hibernate Mappings
« Reply #2 on: February 07, 2007, 10:48:25 am »
Thanks for the response. I have looked into it a little deeper. It looks like Java 5 Annotations may do the trick. Since EA supports annotations as a Tag, I can add the annotations and be done. I need to do some testing to see if it works all the way.

I will let everyone know what I find.