-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: NamingStrategy confusion
PostPosted: Wed Apr 27, 2005 3:41 pm 
Newbie

Joined: Mon Jan 31, 2005 1:33 pm
Posts: 11
Why does the NamingStrategy methods still get called when the table/column property is explicitly set? Here is the behaivor I am seeing using the ImprovedNamingStrategy

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.yahoo.pm.persist.pm" schema="PMCAPS20>
<class name="SvrRole" mutable="false">
<cache usage="read-only"/>
<id name="SvrRoleId"/>
<property name="Name" />
<property name="SvrRoleDescription" >
<column name="SVR_ROLE_DESC"/>
</property>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
List roles = session.createQuery("from SvrRole").list();

The generated SQL (show_sql=true):
10:33:05,934 INFO [STDOUT] Hibernate: select svrrole0_.svr_role_id as svr1_, svrrole0_.name as name6_, svrrole0_.sv_r_rol_e_desc as sv3_6_ from PMCAPS20.svr_role svrrole0_

The primary thing to note is that I want to have a different property name for SvrRoleDescription than the actual column name SVR_ROLE_DESC. Intuition tells me that it should take the column name verbatum if I supply it BUT it actually tries to apply the ImprovedNamingStrategy and it ends up munging the column name to sv_r_rol_e_desc. I looked at the source code and found that it is in fact utilizing the NamingStrategy directly on the column name. This doesn't seem right to me. Am I misunderstanding the role of NamingStrategy?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 02, 2005 6:18 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
naming strategy is applied on the column/table names whether defaulted or not.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 02, 2005 1:01 pm 
Newbie

Joined: Mon Jan 31, 2005 1:33 pm
Posts: 11
I understand that is was designed and coded that way but it doesn't seem to be the correct approach. If I supply a column name with
<column name="SVR_ROLE_DESC"/>
it shouldn't munge it to be sv_r_rol_e_desc. Why would you even look at a supplied column name with a NamingStrategy? It forces the users to always have the column name as their property name verbatim with no exceptions. I understand that the NamingStrategy was created to reduce verbosity in the mapping files but this feels too restrictive.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 02, 2005 1:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
For the Javadoc-challenged:

There are two different methods: propertyToColumnName() and columnName(). You can implement the first instead of the second.

Quite elegant and straightforward, no?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 02, 2005 2:30 pm 
Newbie

Joined: Mon Jan 31, 2005 1:33 pm
Posts: 11
Yes, but, uhh, if you look...damn! Okay, I'll shut up now.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.