[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-6927?page=c...
]
Steve Ebersole resolved HHH-6927.
---------------------------------
Resolution: Rejected
@TypeDefs and hbm.xml can *only* deal with classes, not instances. hbm.xml hopefully for
obvious reasons; and annotations can only deal with pre-determinate values.
This registration of instances is by design. And you actually can register different
parameterizations; you simply do it under different registration keys. Look at the
signatures:
* {{public void registerTypeOverride(BasicType type)}}
* {{public void registerTypeOverride(UserType type, String[] keys)}}
* {{public void registerTypeOverride(CompositeUserType type, String[] keys)}}
All 3 cases deal with this notion of registration keys. For {{BasicType}} it is defined
on its contract. I could easily be talked into a corollary contract for user types,
something like:
{code}
public interface Registrable {
public String[] getRegistrationKeys();
}
{code}
Cannot register a type through configuration if the type is
parametrized
------------------------------------------------------------------------
Key: HHH-6927
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-6927
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.6.5
Reporter: Stephane Nicoll
Since I don't want to hardcode @TypeDefs in each class hierarchy that uses a custom
type, I am using the {{cfg.registerTypeOverride}} method. This works fine for simple user
type but I have a parameterized user type.
In that case, using this method leads to a single user type instance being used and
shared for all my entities and no parameter is injected at all. Looking a bit deeper I
think I found the culprit in TypeResolver.
{code:java}
public Type heuristicType(String typeName, Properties parameters) throws MappingException
{
Type type = basic( typeName );
if ( type != null ) {
return type;
}
try {
Class typeClass = ReflectHelper.classForName( typeName );
if ( typeClass != null ) {
return typeFactory.byClass( typeClass, parameters );
}
}
catch ( ClassNotFoundException ignore ) {
}
return null;
}
{code}
base(typeName) will actually return the type that I have registered. Notice that basic
does not take the {{parameters}} argument into account. Since it's not null it just
returns that type.
Maybe I did something wrong. I was surprised that cfg actually registers *instances* and
not classes. Both @TypeDefs and hbm.xml specifies classes. Maybe adding an option to
register a class programmatically?
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira