facebook

HIbernate Reverse Engineering and Mapping

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #272657 Reply

    ernestz
    Member

    Installation summary:

    *** Date: 
    Thursday, July 12, 2007 10:07:33 AM CDT
    
    ** System properties:
    OS=WindowsXP
    OS version=5.1
    Java version=1.5.0_11
    
    
    *** MyEclipse details:
    MyEclipse Enterprise Workbench
    Version: 5.5.1 GA
    Build id: 20070521-5.5.1-GA
    
    
    *** Eclipse details:
    Eclipse SDK
    
    Version: 3.2.2
    Build id: M20070212-1330
    
    
    
    
    Eclipse Platform
    
    Version: 3.2.2.r322_v20070119-RQghndJN8IM0MsK
    Build id: M20070212-1330
    
    
    Eclipse Java Development Tools
    
    Version: 3.2.2.r322_v20070104-R4CR0Znkvtfjv9-
    Build id: M20070212-1330
    
    
    Eclipse Project SDK
    
    Version: 3.2.2.r322_v20070104-dCGKm0Ln38lm-8s
    Build id: M20070212-1330
    
    
    Eclipse Graphical Editing Framework
    
    Version: 3.2.2.v20070208
    Build id: 20070208-1315
    
    
    Eclipse RCP
    
    Version: 3.2.2.r322_v20070104-8pcviKVqd8J7C1U
    Build id: M20070212-1330
    
    
    Eclipse Plug-in Development Environment
    
    Version: 3.2.1.r321_v20060823-6vYLLdQ3Nk8DrFG
    Build id: M20070212-1330
    
    
    Eclipse Graphical Editing Framework
    
    Version: 3.2.2.v20070208
    Build id: 20070208-1315
    
    
    
    
    Eclipse startup command=-os
    win32
    -ws
    win32
    -arch
    x86
    -launcher
    C:\eclipse\eclipse.exe
    -name
    Eclipse
    -showsplash
    600
    -exitdata
    186c_790
    -vm
    C:\WINDOWS\System32\javaw.exe

    I am starting to use Hibernate and came across a problem, I think and wanted to confirm my usage.

    Basically, I have some tables which have some non-conventional column names, Some columns begin with “#”, some have “/” in the column name.

    When I reverse engineer a table, I go to the third (or last) ‘dialog’ in the Hibernate Reverse Engineering . I expand the table in the Generate artifacts for the following tables and scroll down to the non-conventional columns. For each such column, I enter a valid Java Property name. I do this for each of the problematic columns.

    When I click Finish, the POJO and DAO classes are created, but with syntax errors, as these properties are created using the default column names, ignoring the mappings I entered.

    For example, one column is named ‘# Hours’. In the above scenario, I entered/mapped the column to a property name numHours. The POJO generated had the property called #Hours.

    Did I follow the correct process for mapping non-conventional column names to valid Java property names? I have several such tables and would rather not have to go back and manually fix all source/xml files.[/b]

    #272658 Reply

    ernestz
    Member

    I forgot to mention, after I see the classes have been generated, I can go back to the Reverse Engineering dialogs and see that the mappings are still there.

    #272768 Reply

    Riyad Kalla
    Member

    I have asked someone from our persistence team to take a look at this.

    #272774 Reply

    Brian Fernandes
    Moderator

    ernestz,
    Sorry for the delay in getting back to you – I cannot think of why this is happening; yes, you are following the correct steps.

    I have a few questions:

    1) Have you specified a RE Strategy class? (this is a custom class that can be used to control the RE process besides the RE settings on page 3)
    2) Are you customizing anything else other than the property names – have you ever edited the resulting hibernate.reveng.xml file generated by hand? This is the file that stores all the RE settings you might make on page 2 and 3 of the wizard.
    3) Delete (or rename) the hibernate.reveng.xml file in your project root and try making just a single setting on page 3 again. Does it work? You could also try generating into a dummy hibernate project and see if that works.
    4) Are there any errors logged after you complete the RE process? More details on how to spot errors logged can be found in this thread: Posting Guidelines

    If the above don’t fix the issue for you, can you send me the hibernate.reveng.xml file from your project? Mail it to support@genuitec.com ATTN Brian.

    #272780 Reply

    ernestz
    Member

    @Support-Brian wrote:

    ernestz,
    Sorry for the delay in getting back to you – I cannot think of why this is happening; yes, you are following the correct steps.

    No problem
    @Support-Brian wrote:

    I have a few questions:

    1) Have you specified a RE Strategy class? (this is a custom class that can be used to control the RE process besides the RE settings on page 3)

    No.

    @Support-Brian wrote:

    2) Are you customizing anything else other than the property names – have you ever edited the resulting hibernate.reveng.xml file generated by hand? This is the file that stores all the RE settings you might make on page 2 and 3 of the wizard.

    No other customizations or editing of any files.

    Here is a sequence of events I am going through as I am describing the problem:

    I just started with a new java project and added Hibernate 3.1 capabilities, for MS SQL Server, all new/clean hibernate configuration/mapping/xml files.

    I go to the Database Explorer perspective and select one of the tables with a non-conventional column name (in this case, the table has one column named “# Hours”). I right-click and select “Hibernate Reverse Engineering” from the popup menu.

    From the first dialog, I enter the Java package, check “Hibernate mapping file for each database table”, check “Update hibernate configuration with the mapping file location”, check “Java Data Object (POJO -> DB Table)” (no abstract class), check “Java Data Access Object (DAO)”, check “Generate precise findBy methods”, select “Basic DAO” with base class “<Default Base DAO> (recommended)”. Hit Next.

    I do not modify anything on the second dialog. Hit Next.

    On the third dialog, I expand the table listed under the section entitled “Generate artifacts for the following table”. I scroll down to the column name that I want to remap, in this case the column is called “# Hours”. Under the section entitled “Column details”, I simply enter a new “Property Name” of “numHours” and hit Finish. Nothing else is changed on this dialog other than the “Property Name” for column I am trying to map.

    I click on Finish and the POJO and DAO classes are generated for the table. But, there are syntax errors because the property names I tried to specify to are not used. Rather, the default columns names are used. So my mapping of a column named “# Hours” becomes a Java property name of “#Hours” instead of the preferred mapping name of “numHours”.

    @Support-Brian wrote:

    3) Delete (or rename) the hibernate.reveng.xml file in your project root and try making just a single setting on page 3 again. Does it work? You could also try generating into a dummy hibernate project and see if that works.

    Started with a new project to document my response to Step 2 above. Problem persists.

    @Support-Brian wrote:

    4) Are there any errors logged after you complete the RE process? More details on how to spot errors logged can be found in this thread: Posting Guidelines

    I checked the “.log” file in my workspace/.metadata directory and there are no errors logged around the time I’m RE’ing. I even exited Eclipse, deleted the .log file, and lauched Eclipse and went through the above scenario. No errors were logged.

    I had previously gone back and manually corrected the “mis-mappings”, but would prefer to automate this for future regeneration of class source files, or possibly other projects using non-conventional column names.

    #272782 Reply

    ernestz
    Member

    I wanted to add that after the RE described, the “hibernate.reveng.xml” appears to have the correct information, as near as I can tell. But here is the file which results after my described scenario in the previous post:

    <?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 name="Course Table" schema="dbo">
            <column name="# Hours" property="numHours"/>
        </table>
    </hibernate-reverse-engineering>
    
    #272784 Reply

    Brian Fernandes
    Moderator

    Just confirming that you are following the correct steps.

    I have a few additional suggestions
    1) What is the fully qualified name of the table you are reverse engineering from – my guess is [catalogName].dbo.[tableName], right?
    2) Can you try customizing the property name of a column which has a simple name with no special characters and see if that works?
    3) Can you send me the hibernate.reveng.xml file from your project, it only contains the customizations you have made. Email it to support@genuitec.com ATTN Brian. This should help be track down the issue faster.
    4) If you do have another database up and running, could you try reverse engineering a sample table from that and see if your customizations work?

    #272801 Reply

    ernestz
    Member

    I believe I found the problem.

    I tried to RE another table in the database with no columns containing special characters (although some of the column names did have spaces). I followed the steps I previously documented and tried to map one of the column names, only to have the resulting classes use the standard column name and not my mapped property name.

    While experimenting a little more, I found that I had to enter a fully qualified class name for the table on the third dialog, something I did not do before. So, on the third dialog of the RE process, I click on the table listed under the “Generate artifacts for the following tables”. On the right side of the dialog, I enter the fully qualified “Class name” (full package specification).
    Then, I can map any column names I want and the mapping actually takes place. I had never actually entered a class name for the table before, just property names.

    Here is the “hibernate.reveng.xml” from my problem report from yesterday.

    <?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 name="Course Table" schema="dbo">
            <column name="# of Hours" property="numHours" />
        </table>
    </hibernate-reverse-engineering>

    This morning, I went through the same steps, but this time, I entered a fully quallified class name for the table in question and everything seems to work. Here is the “hibernate.reveng.xml” from this morning:

    <?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 name="Course Table" schema="dbo" class="test.t1.CourseTable" catalog="T1">
            <column name="# of Hours" property="numHours" />
        </table>
    </hibernate-reverse-engineering>

    So, I guess in order to have a property mapping work, I should always specify a fully qualified class name for any table for which I need to provide column name mapping.

    #272819 Reply

    Brian Fernandes
    Moderator

    ernestz,

    It isn’t the FQN that “fixes” it, it is the the fact that in the 2nd snippet, the table has both a schema and catalog qualifier. Note the catalog = “TI” attribute.

    What seems to have happened is, when you customize the class name, the wizard inserts both the catalog and the schema name into the reveng.xml file; when you customize only the column name, the wizard inserts only the schema name – this is a bug and we’ll try to get this fixed in the upcoming 6.0GA release.

    The work around until then is to simply continue as before without specifying FQNs for the classes unless you need to. Open up the generated reveng.xml file and add the catalog = “TI” attribute to all the table elements. The next time you reverse engineer, your custom mappings should be picked up. Of course, as you discovered, you could lso specify the FQNs to fix it – you could even delete them in subsequent generation passes, the catalog attribute will remain and the mapping will still work.

    Thanks for helping us track this down, we appreciate it.

Viewing 9 posts - 1 through 9 (of 9 total)
Reply To: HIbernate Reverse Engineering and Mapping

You must be logged in to post in the forum log in