[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3000) Allow a TypeDef to be associated with a class

Sharath Reddy (JIRA) noreply at atlassian.com
Sat Aug 15 09:11:15 EDT 2009


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3000?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=33760#action_33760 ] 

Sharath Reddy commented on HHH-3000:
------------------------------------

This is already possible, without needing to add the 'targetClass' attribute.

Suppose we have a custom class called 'hello.Dog', and we want to use the custom user type 'hello.DogUserType' to persist and retrieve it:

import hello.Dog;

@TypeDef(name="hello.Dog", typeClass=hello.DogUserType.class) //'hello.Dog' is the fully-qualified class name of our custom class

class XX {
    private Dog dog;   //No @Type annotation necessary; Hibernate realizes it has to use DogUserType to persist/retrieve this property

This is possible because of the following lines in SimpleValueBinder:
String type = BinderHelper.isDefault( explicitType ) ? returnedClassName : explicitType;
org.hibernate.mapping.TypeDef typeDef = mappings.getTypeDef( type );

If 'explicitType' is not set (via the 'Type' attribute), it uses 'returnedClassName' ('hello.Dog' in this example) as the key to look-up the associated Type info. Since we have previously registered the TypeDef with the same key (hello.Dog), it is able to retrieve the value correctly.

Probably this issue can be closed. Or else, I could submit a patch to add the 'targetClass' attribute....

> Allow a TypeDef to be associated with a class
> ---------------------------------------------
>
>                 Key: HHH-3000
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3000
>             Project: Hibernate Core
>          Issue Type: Improvement
>            Reporter: Darren Bell
>
> This would allow you to just define it once and not have to worry about adding extra details to the mapping file or by annotating a field.
> For instance:
> 	@TypeDef(
> 		name="internalHeaderType",
> 		typeClass=com.dolby.mapics.GenericEnumUserType.class,
>                 targetClass=com.dolby.mapics.InternalHeaderType,
> 		parameters= {
> 			@Parameter(name="enumClass", value="com.dolby.mapics.InternalHeaderType"),
> 			@Parameter(name="identifierMethod", value="toString"),
> 			@Parameter(name="valueOfMethod", value="fromString")
> 	})
> by adding the targetClass attribute would enable this.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list