- This topic has 11 replies, 4 voices, and was last updated 18 years, 9 months ago by Steve Prior.
-
AuthorPosts
-
Seagate_UKMemberHi,
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 WorkbenchVersion: 4.0.100 M1
Build id: 20051103-4.1-Milestone1*** Eclipse details:
Eclipse SDKVersion: 3.1.0
Build id: I20050627-1435Eclipse Platform
Version: 3.1.0
Build id: I20050627-1435Eclipse Java Development Tools
Version: 3.1.0
Build id: I20050627-1435Eclipse Project SDK
Version: 3.1.0
Build id: I20050627-1435Eclipse RCP
Version: 3.1.0
Build id: I20050627-1435Eclipse Plug-in Development Environment
Version: 3.1.0
Build id: I20050627-1435Eclipse 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.exethanks
Martin
Riyad KallaMemberMartin
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
Seagate_UKMemberThanks 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
Riyad KallaMemberSo 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)
Seagate_UKMemberSo there are no immediate plans to have an all encompassing naming strategy selection for the mapping generation?
Brian FernandesModeratorMartin,
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.
Seagate_UKMemberBrian,
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
Brian FernandesModeratorMartin,
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.
Steve PriorMemberI’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.
Brian FernandesModeratorSprior,
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.
Steve PriorMemberI see the ability to override property names, but don’t see the ability to override the name of the class itself.
Steve PriorMemberI 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.
-
AuthorPosts