Saturday, May 23, 2009

hibernate code generation

Now a days, I'm working on a server side backend service that exposes an API using a REST interface. To get to the data model, we first created a business domain model which contained business entities, value objects and some enumerations. From this domain model we created a ER diagram and from there a db data model. Next comes the ORM layer(using hibernate) and we figured out that there were two ways to go...
  1. Write hibernate hbm files and generate code and db-scripts from them.

  2. Create db-scripts from the data-model and reverse engineer this schema to generate hibernate classes and hbm files

At the moment we decided that we want to keep a close grip on what gets created inside db, so we went ahead with the second approach. After some use it looks like, we're taking alot of pain in work-arounds to not to touch generated java code(so that we can change data model anytime and regenerate the code). Let us see if this approach works out fine or if at some point we switch to 1st approach and start modifying the hbm files and generate db-scripts from them.

5 comments:

  1. Himanshu,
    my 2 cents, but you should be talking to your architect, rather than struggle with this monstrosity of an approach to ORM.

    This whole sequence is broken in so many ways. Talk to me off line if you need more clarification.

    Once you come to a choice point with the two options above (and as I said above the sequence is broken). option *1* is the correct one, not option 2.


    This part "From this domain model we created a ER diagram and from there a db data model." is really scary! ;-)


    fwiw. my 2 cents.

    ReplyDelete
  2. "option *1* is the correct one, not option 2."

    Add "partly" as a qualifier!

    ReplyDelete
  3. Hey Ravi, Thanks for the pointers. We've also had the same feeling that *option-1* is THE right approach. As we go along we plan to switch our strategy from option-2 to option-1 that is down the line, we'll start working directly on the generated java classes & hbm files and generate db scripts from them.

    Regarding domain-model->ER-diagram->data-model, I don't know if its right or wrong but seems to have worked in our case ;-)

    ReplyDelete
  4. "option-1* is THE right approach. "

    Given that you come to that choice point! You don't need to :-)

    "we'll start working directly on the generated java classes & hbm files and generate db scripts from them."

    This is (almost) gobbledegook, but since you guys want to proceed this way, let's leave it at that. I'll speak to you 6 months later :-D

    "Regarding domain-model->ER-diagram->data-model, I don't know if its right or wrong but seems to have worked in our case ;-)"

    I like the ;-)!

    ;-)

    ReplyDelete
  5. looks like we're gonna learn a few lessons down the road the hard way... ;)

    ReplyDelete