-->
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.  [ 4 posts ] 
Author Message
 Post subject: Bug in NamingStrategy (?)
PostPosted: Mon Dec 19, 2005 3:19 pm 
Regular
Regular

Joined: Tue Nov 16, 2004 6:36 pm
Posts: 62
Location: Zürich
Hibernate version: 3.1 final

Hello,

I use the ImprovedNamingStrategy to map properties to column names.
In 3.1rc1 all was still working fine, but now in 3.1 final the configured ImprovedNamingStrategy seems to be applied a bit "too much".

An excerpt from the mapping file:
Code:
   
<class name='AbstractBenchmark' table='se_benchmark'>
        <id name='id'>
            <generator class="native">
                <param name='sequence'>se_abm_seq</param>
            </generator>
        </id>
        <property name='asofDate' type='date'/>
       
        <component name="editStatus" class="com.csg.pmnet.model.EditStatus">
            <property name="editPid" column='edit_pid'/>


The property asofDate still is properly mapped to the column asof_date.
However the property editStatus.editPid is mapped to edit_status_edit_pid. The generated sql shows :

Code:
select abstractbe0_.id as id51_, abstractbe0_.asof_date as asof6_51_, abstractbe0_.edit_status_edit_pid as edit8_51_,
....


It looks like the naming strategy is trying to apply itself to the component property name as well (transforming editStatus into edit_status) which doesn't make sense.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 19, 2005 3:34 pm 
Regular
Regular

Joined: Tue Nov 16, 2004 6:36 pm
Posts: 62
Location: Zürich
By the way, this is how I configured the ImprovedNamingStrategy:

Code:
sessionFactory = new Configuration().setNamingStrategy(ImprovedNamingStrategy.INSTANCE).configure().buildSessionFactory();


as described in the ref.manual. This is correct, isn't it?

Now I have done a bit of debugging, and found out that propertyToColumnName(String propertyName) is called with propertyName equal to "editStatus.editPid". The complete string is passed to addUnderscores, which replaces the . with an _.

rc2 must have done something differently, since we didn't have a problem then.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 19, 2005 3:56 pm 
Regular
Regular

Joined: Tue Nov 16, 2004 6:36 pm
Posts: 62
Location: Zürich
OK I have downloaded the working 3.1rc2, and the differency must be in HbmBinder.java.

Around line 1775, in method bindComponent, I see the difference that I think is significant:

new (not working):

Code:
         else if ( "property".equals( name ) || "key-property".equals( name ) ) {
            value = new SimpleValue( component.getTable() );
            String relativePath;
            if (isEmbedded) {
               relativePath = propertyName;
            }
            else {
               relativePath = subpath.substring( component.getOwner().getEntityName().length() + 1 );
            }
            bindSimpleValue( subnode, (SimpleValue) value, isNullable, relativePath, mappings );
         }



old (working):
Code:
                        else if ( "property".equals( name ) || "key-property".equals( name ) ) {
                                value = new SimpleValue( component.getTable() );
                                bindSimpleValue( subnode, (SimpleValue) value, isNullable, propertyName, mappings );
                        }



new the relativePath (which is editStatus.editPid) instead of just the propertyName (editPid) is passed. I think I'll change it back in my environment even though I'm not sure what the idea of this change was.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 19, 2005 4:31 pm 
Regular
Regular

Joined: Tue Nov 16, 2004 6:36 pm
Posts: 62
Location: Zürich
This is really a monologue, but maybe this is useful for some readers:

I decided against modifying HbmBinder. Looking better I realized that this is intended behaviour (quite strange to make such a change after a release candidate). I think this leads to excessively long column names, also for the map indexes with components as element etc, and if you have nested components you get column names which easily exceed max. size of oracle column names.

So I subclassed ImprovedNamingStrategy and have overwritten the property ToColumnName method:

Code:
    public String propertyToColumnName(String propertyName) {
        return addUnderscores(StringHelper.unqualify(propertyName));
    }


to retain the old behaviour. I think the old behaviour is better. In the rare cases where you need to discern two components that would lead to a naming conflict, you can (have to) overwrite the column name. This is clear and easily detectible.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.