5 Replies Latest reply on Jan 7, 2009 7:30 AM by kvudaykumar

    Hibernate Code Generation

    kvudaykumar

      I wanted to use Hibernate code generation using reverse engineering. I know Java and JDBC but fairly new to Eclipse and Hibernate.

      Setup - Eclipse 3.4 , MySql5.1 (Database)

      Downloaded the plugins from http://download.jboss.org/jbosstools/updates/nightly/trunk/ 2 days back.
      (From one of the forums I found stable JBoss Tools realease for only Eclipse 3.3)

      With the help of document provided by the JBOSS team http://docs.jboss.org/tools/3.0.0.CR1/en/hibernatetools/html_single/index.html
      As described in the section of 4.5. Reverse Engineering and Code Generation, Opened Hibernate Code Generation Dialog...

      In the main tab selected the checkbox "Reverse Engg from JDBC" apart from what specified in the screen shot in Fig 4.11

      and in the Exporters tab selected 1.Domain Code, 2. Hibernate XML Mappings, 3. DAO Code, 4. Hibernate XML configuration

      but didn't specify any exporter properties and tried running it. I expected it generates the above selected files. But in turn it opened "Hibernate Reverse Engg Editor" as in Figure 4.21 and generated only reveng.xml

      I could see the database connection is successful and can see the schema and tables also.

      MySQL driver and Hibernate3 are there in the classpath. And from project properties Hibernate has been selected successfully.

      Can you any one please let me know where I'm missing do I need to do any thing else.

      Regarding documentation :
      JSF Tools Reference Guide(html) (html single) (pdf)
      JSF Tools Tutorial(html) (html single) (pdf)

      Struts Tools Reference Guide(html) (html single) (pdf)
      Struts Tools Tutorial(html) (html single) (pdf)

      Hibernate Tools Reference Guide(html) (html single) (pdf)
      (Don't see Tutorial like JSF, Struts) Please let me any tutorial is there. Did see some turorials in eclipse help but wanted to see tutorial based the what we did with the help of Reference Guide.

      Thanks a lot in advance.


        • 1. Re: Hibernate Code Generation
          maxandersen

          if it opened a reveng.xml file it must have been generated with some content. What is in it ? It maybe be the one preventing the generation ?

          • 2. Re: Hibernate Code Generation
            kvudaykumar

            Thanks for the quick response

            pasting the hibernate.reveng.xml content generated :

            Is there any place where I can find the log / is there any window where need to check for the logs to proceed?

            <?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
            <hibernate-reverse-engineering>
            <type-mapping>
            <sql-type jdbc-type="VARCHAR" hibernate-type="string"
            length="50" not-null="true">
            </sql-type>
            <sql-type jdbc-type="INTEGER" hibernate-type="int"
            not-null="true">
            </sql-type>
            <sql-type jdbc-type="VARCHAR" hibernate-type="string"
            length="250" not-null="true">
            </sql-type>
            <sql-type jdbc-type="VARCHAR" hibernate-type="string"
            length="100" not-null="true">
            </sql-type>
            </type-mapping>
            <table-filter match-schema="struts-hibernate" match-name=".*" />

            <primary-key></primary-key>
            <column name="shortdesc" jdbc-type=''>
            <column name="longdesc" jdbc-type=''>
            <column name="pageurl" jdbc-type=''>

            </hibernate-reverse-engineering>

            • 3. Re: Hibernate Code Generation

              I've just created a java project with hibernate , connected to MySQL and generated the files using reverse engineering quite successfully.

              This is my .reveng.xml file
              <?xml version="1.0" encoding="UTF-8"?>
              <!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >

              <hibernate-reverse-engineering>
              <table-filter match-name="table-name" match-catalog="database"></table-filter>
              </hibernate-reverse-engineering>

              I think you need to click the "Table Filters" view and there select the table you want to work with.

              I guess you used "Type Mappings" to generate your reveng.xml file

              I also recommend you to watch our demo video that shows how you can generated those files.

              http://docs.jboss.org/tools/movies/demos/Reverse_engineering_and_code_generation/Reverse_engineering_and_code_generation.htm

              • 4. Re: Hibernate Code Generation
                maxandersen

                that reveng.xml looks incomplete - the xml is not balanced.

                Did you intentionally create that file ? I would suggest removing it just to see if it works fine without and then after that start filtering it.

                • 5. Re: Hibernate Code Generation
                  kvudaykumar

                  I generated the code successfully.

                  reveng.xml was generated automatically only. When code generation was not working then I tried different options and finally I got the xml content.

                  Thanks a lot especially for the demo.