Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
martindonaghy
Post subject: Hibernate not dealing with database naming conventions  PostPosted: Dec 09, 2005 - 03:03 PM



Joined: Mar 01, 2005
Posts: 11

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:

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


When MyEclipse generates the java class this it produces:

Code:
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.1\eclipse\eclipse.exe
-name
Eclipse
-showsplash
600
-exitdata
d50_70
-vm
C:\WINDOWS\system32\javaw.exe

thanks
Martin
 
 View user's profile Send private message  
Reply with quote Back to top
support-rkalla
Post subject:   PostPosted: Dec 09, 2005 - 03:33 PM
Registered Member
Registered Member


Joined: Jan 06, 2004
Posts: 23855

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:
http://www.myeclipseide.com/index.php?name=PNphpBB2&file=viewtopic&t=9661&postdays=0&postorder=asc&start=0

_________________
Riyad
MyEclipse Support
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
martindonaghy
Post subject:   PostPosted: Dec 09, 2005 - 03:48 PM



Joined: Mar 01, 2005
Posts: 11

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
 
 View user's profile Send private message  
Reply with quote Back to top
support-rkalla
Post subject:   PostPosted: Dec 09, 2005 - 04:27 PM
Registered Member
Registered Member


Joined: Jan 06, 2004
Posts: 23855

Quote:

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)

_________________
Riyad
MyEclipse Support
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
martindonaghy
Post subject:   PostPosted: Dec 09, 2005 - 04:41 PM



Joined: Mar 01, 2005
Posts: 11

So there are no immediate plans to have an all encompassing naming strategy selection for the mapping generation?
 
 View user's profile Send private message  
Reply with quote Back to top
Support-Brian
Post subject:   PostPosted: Dec 09, 2005 - 04:50 PM
Moderator
Moderator


Joined: Aug 21, 2004
Posts: 2339

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.

_________________
Brian
MyEclipse Support
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
martindonaghy
Post subject:   PostPosted: Dec 09, 2005 - 05:03 PM



Joined: Mar 01, 2005
Posts: 11

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
 
 View user's profile Send private message  
Reply with quote Back to top
Support-Brian
Post subject:   PostPosted: Dec 09, 2005 - 10:26 PM
Moderator
Moderator


Joined: Aug 21, 2004
Posts: 2339

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.
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
sprior
Post subject:   PostPosted: Jan 13, 2006 - 10:56 PM
Registered Member
Registered Member


Joined: Nov 02, 2005
Posts: 157

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.
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
Support-Brian
Post subject:   PostPosted: Jan 14, 2006 - 05:30 AM
Moderator
Moderator


Joined: Aug 21, 2004
Posts: 2339

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.
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
sprior
Post subject:   PostPosted: Jan 16, 2006 - 04:02 PM
Registered Member
Registered Member


Joined: Nov 02, 2005
Posts: 157

I see the ability to override property names, but don't see the ability to override the name of the class itself.
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
sprior
Post subject:   PostPosted: Jan 16, 2006 - 04:11 PM
Registered Member
Registered Member


Joined: Nov 02, 2005
Posts: 157

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.
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT - 6 Hours
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits