ImprovedNamingStrategy unqualifies property names - blocks the use of several composite types in the same entity

Description

Seems like ImprovedNamingStrategy unqualifies property names when processing column names.
I'm using EJB binding, and the strategy gets a property value like "somecomposite.foo" and "somecomposite.bar".

Now, if I want to use a composite typed property several times in an Entity, the base property name is removed (like "somecomposite"). If I have an entity with 2 composite properties:

public FooComposite getComposite1();
public FooComposite getComposite2();

ImprovedNamingStrategy should map it as "composite1.foo", "composite1.bar". Instead, we get "foo" and "bar" alone, and when mapping Composite2 Hibernate throws a MappingException: "org.hibernate.MappingException: Same logical column name referenced several times"

If we change:

public String logicalColumnName(String columnName, String propertyName) {
return StringHelper.isNotEmpty( columnName ) ? columnName : StringHelper.unqualify( propertyName );
}

For this:

public String logicalColumnName(String columnName, String propertyName) {
return StringHelper.isNotEmpty( columnName ) ? columnName : addUnderscores( propertyName );
}

The problem would get solved, I think.

Environment

None

Activity

Show:
Leonardo Quijano
November 23, 2005, 7:47 AM

Same happen with foreign keys, and I think with all unqualified property names:

public String foreignKeyColumnName(String propertyName, String propertyTableName, String referencedColumnName) {
String header = propertyName != null ? StringHelper.unqualify( propertyName ) : propertyTableName;
if (header == null) throw new AssertionFailure("NammingStrategy not properly filled");
return columnName( header ); //+ "_" + referencedColumnName not used for backward compatibility
}

Changed to ..

public String foreignKeyColumnName(String propertyName, String propertyTableName, String referencedColumnName) {
String header = propertyName != null ? addUnderscores( propertyName ) : propertyTableName;
if (header == null) throw new AssertionFailure("NammingStrategy not properly filled");
return columnName( header ); //+ "_" + referencedColumnName not used for backward compatibility
}

(2nd line "addUnderscores")

GavinG
November 26, 2005, 11:15 AM

So write your own naming strategy. It's an extension pt.

Leonardo Quijano
November 29, 2005, 10:24 AM

(actually trying to improve the framework)

The bug is on the default strategy. I know is an extension point.
The default is broken, for the reasons specified above.

Emmanuel Bernard
November 29, 2005, 11:47 AM

I kept this value in purpose for backward compatibility.
Use DefaultComponentSafeNamingStrategy in HA to achieve what you want.

Leonardo Quijano
November 29, 2005, 5:56 PM

Thanks for the clarification. I had already one based on that. The issue was on the default one, with if it's needed for backward compatibility, great .

Won't Fix

Assignee

Unassigned

Reporter

Leonardo Quijano

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure