• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

My hibernate generator

 
Ranch Hand
Posts: 120
IntelliJ IDE Hibernate Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote my own HBM generator that can be used by everybody else. So if you use MSSQL or MYSQL you can find this generator usefull.

This ANT script is a generator for Hibernate mapping files. Generator can create a JAR file that contains set of generated HBM and class files. One HBM file and one class file are generated for every mapped table. You can select subset of the table, provide exact Java types mapping of every supported SQL type, select hibernate version, choose a primary key generator. After JAR file is generated you can add it to your project in order to connect your project to the database using Hibernate framework. After you add Jar file to your project you have to change your hibernate configuration file and add the references to generated HBM files. For your convenience, text file that has list of mapped files is also generated.

hbm4stas
[ May 03, 2006: Message edited by: Stas Sakalou ]
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Um, why not just use XDoclet to generate your files? If you use Hibernate 3.0 just use Annotations.

Curious, I might be missing something here. Or are you generating the .java and xml from the database, which Hibernate has tools that do this too. I'm lost, sorry.

Mark
 
Stan Sokolov
Ranch Hand
Posts: 120
IntelliJ IDE Hibernate Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Um, why not just use XDoclet to generate your files? If you use Hibernate 3.0 just use Annotations.

Curious, I might be missing something here. Or are you generating the .java and xml from the database, which Hibernate has tools that do this too. I'm lost, sorry.

Mark


I dont know what to say :-)
At the time I started writing this stuff it was the only tool available that can scan DB and create HBM files for every found table. It was a middlegen. But middlegen is always(!) generating relationships between tables if both tables have fields with the same name. For example member.name and provider.name. These fields might have different meaning but middlegen still goes ahead with generation relationship.

Because I needed some tool that can go trough the DB and create me mapping files I wrote this tool myself.

Probably now there is something else that does this work better...
Just let me know where I can find this new tool. Thank you.
[ May 04, 2006: Message edited by: Stas Sakalou ]
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I did a Google search for middlegen and saw that it uses XDoclet. Here is XDoclet's web site.

Hibernate also has a generation tool.

Mark
 
Stan Sokolov
Ranch Hand
Posts: 120
IntelliJ IDE Hibernate Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
XDoclet and Hibernate annotations are reverse mapping tools.
They map java classes to HBM files. That has a little practical usage for the heterogeneous projects.

Java->HBM mapping makes sense for the projects that are completely driven by Java code. What is not the case in the big distributed projects where single DB might be used by applications written using different languages. In this case DB->HBM->Java DTO mapping is required to easily update DTO objects after DB was changed. Let take an example.
Imagine that DB has 400 tables. Many of these tables were changed due to new requirements. Now, it is required to regenerate DTO in order to take latest changes made by DB admin and also replace class that is used as PK generator.
My generator allows you to do this in 2-3 minutes... Probably there are other tools that are doing the same job but it looks for me that Hibernate Annotations and xDoclet are not in this list.

Middlgen can do dirrect DB->HBM mapping but, as I didnt said, using velocity templates. Unfortunatly at the time I was using it, Middlegen generator was very unflexable in its configuration: Relationship mapping could not be switched off for example, primary key generator class could not be configured for individual tables and some other restrictions were implied.

Eclispse plugins
There is a beta-version of some "eclipse-only-working" project that supports reverse engeenering approach. It does about the same job as my generator does and it also allows to map relationship that I currently do not support.

[ May 04, 2006: Message edited by: Stas Sakalou ]

[ May 04, 2006: Message edited by: Stas Sakalou ]

[ May 04, 2006: Message edited by: Stas Sakalou ]

[ May 04, 2006: Message edited by: Stas Sakalou ]

[ May 04, 2006: Message edited by: Stas Sakalou ]

[ May 04, 2006: Message edited by: Stas Sakalou ]
[ May 04, 2006: Message edited by: Stas Sakalou ]
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, Hibernate has a tool that takes the DB stucture and creates mapping file and then java code. That is what I am saying that you can go any direction you want with Hibernate tools that already exist. The XDoclet was pre-Annotations to allow you to keep the mapping and Java in one file.

Mark
 
I'm thinking about a new battle cry. Maybe "Not in the face! Not in the face!" Any thoughts tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic