facebook

Hibernate not dealing with database naming conventions

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

    Seagate_UK
    Member

    Hi,

    We have naming conventions applied to our database tables where the table name will have a three letter prefix plus underscore, e.g. Voter will have a table called App_Voter. Within this table the field names also have prefixes to ensure they are unique across the database and save on adding table aliases in sql statements. Within the App_Voter table there are the fields V_Id, V_PollNo, etc.

    When MyEclipse generates the mapping file for this it produces the line:

            <id name="vId" column="V_Id" type="integer">
                <generator class="native"/>
            </id>

    When MyEclipse generates the java class this it produces:

    public java.lang.Integer getVId()

    So when the hibernate har file is deployed on JBoss 4.0.3 it throws the exception:

    org.hibernate.PropertyNotFoundException: Could not find a getter for vId in class com.opt2vote.hibernate.AppVoter.

    I have tracked this down to the fact that Hibernate is expecting the get method to be getvId, but this isn’t normal java practice. Basically, there seems to be a problem with field names where there is one letter then an underscore. Multiple letters then an underscore seems to work. I think that its the mapping file generation within MyEclipse that has got it wrong.

    What do you think?

    As a workaround we are going to make sure our database has multiple letter prefixes. Also, is there any way to tell Hibernate about database naming conventions so that they don’t clutter the code?

    My setup is as follows:

    *** Date: Fri Dec 09 14:41:04 GMT 2005

    *** System properties:
    OS=WindowsXP
    OS version=5.1
    Java version=1.5.0_06

    *** MyEclipse details:
    MyEclipse Enterprise Workbench

    Version: 4.0.100 M1
    Build id: 20051103-4.1-Milestone1

    *** Eclipse details:
    Eclipse SDK

    Version: 3.1.0
    Build id: I20050627-1435

    Eclipse Platform

    Version: 3.1.0
    Build id: I20050627-1435

    Eclipse Java Development Tools

    Version: 3.1.0
    Build id: I20050627-1435

    Eclipse Project SDK

    Version: 3.1.0
    Build id: I20050627-1435

    Eclipse RCP

    Version: 3.1.0
    Build id: I20050627-1435

    Eclipse Plug-in Development Environment

    Version: 3.1.0
    Build id: I20050627-1435

    Eclipse startup command=-data
    C:\development\workspace
    -os
    win32
    -ws
    win32
    -arch
    x86
    -launcher
    C:\Program Files\eclipse\3.1\eclipse\eclipse.exe
    -name
    Eclipse
    -showsplash
    600
    -exitdata
    d50_70
    -vm
    C:\WINDOWS\system32\javaw.exe

    thanks
    Martin

    #242921 Reply

    Riyad Kalla
    Member

    Martin
    Please have a look at this thread, especially the last 3 posts of Page 1 and Page 2, it doesn’t seem to be an ME bug, just invalid property names:
    https://www.genuitec.com/forums/topic/hibernate-foreign-keys-mapping-wrong-getters-and-setters/&postdays=0&postorder=asc&start=0

    #242922 Reply

    Seagate_UK
    Member

    Thanks again. Sorry didn’t see that post. Came up with the same solution though!
    So is there any way to tell hibernate/myeclipse about naming conventions for mapping file/java class generation?

    Martin

    #242929 Reply

    Riyad Kalla
    Member

    So is there any way to tell hibernate/myeclipse about naming conventions for mapping file/java class generation?

    Not currently, but there is a lot of work being done for our 4.1 M2 release (due out on the 19th) that I believe I remember from a review will allow you to set property names now. Although it includes a huge manual step in the mapping generation, you may just want to adjust the table names as a longer term solution (as other hibernate synchronization plugins will likely suffer the same fate)

    #242931 Reply

    Seagate_UK
    Member

    So there are no immediate plans to have an all encompassing naming strategy selection for the mapping generation?

    #242933 Reply

    Brian Fernandes
    Moderator

    Martin,

    We don’t have immediate plans to support specifying a mapping strategy; in m2 however, you will be able to override the property names.

    We are aware of the need for a mapping strategy and as soon as we have the basic functionality squared off, we’ll get right to it.

    Best,
    Brian.

    #242936 Reply

    Seagate_UK
    Member

    Brian,

    Thanks. It would be a very useful feature indeed. One small question off this topic if you please. Named queries – they usually are placed in the mapping files. Is there an alternative place to store these so they are preserved during mapping generation? Also, has MyEclipse any way of running these queries as standalone?

    thanks
    Martin

    #242954 Reply

    Brian Fernandes
    Moderator

    Martin,

    I see your point about Named queries, unfortunately there isn’t a way to preserve them yet. That would probably have to wait until we have our Visual Mapping editor.

    There currently isn’t a way to execute these either, but we’ll investigate this issue.

    Best,
    Brian.

    #244566 Reply

    Steve Prior
    Member

    I’d like to add my vote for allowing for Java class/property name overrides when reverse engineering Hibernate mappings from tables. At my company we have a convention of naming tables ending in _rtab for full fledged tables and _enum for tables which are used as enumerations for foreign keys. When generating the Java classes for Hibernate these suffixes are left in and I had to change them all manually.

    #244577 Reply

    Brian Fernandes
    Moderator

    Sprior,

    The 3rd page of the Hibernate RE wizard allows overriding of property names (since 4.1M2). The settings are saved as usual for future RE operations.
    Is this what you want or does it fall short somewhere?

    Best,
    Brian.

    #244634 Reply

    Steve Prior
    Member

    I see the ability to override property names, but don’t see the ability to override the name of the class itself.

    #244642 Reply

    Steve Prior
    Member

    I should expand on my last a little. I don’t see the ability to override the name of the java class that is generated from reverse engineering a database table, I just see the properties inside that class. And if the function to override the class name was added, it should take place first, before the property names for the associations were created so that the collection properties would use the overridden class name in generating the name of the property, not the original.

    Longer term (since it’s probably harder to do), I’d like to see refactor->rename work to rename these properties and classes in both the hibernate mapping files as well as the Java itself.

Viewing 12 posts - 1 through 12 (of 12 total)
Reply To: Hibernate not dealing with database naming conventions

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