[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-1097) No way to access directly access UserType in Interceptor

Tom Coogan (JIRA) noreply at atlassian.com
Mon Mar 12 11:46:48 EDT 2012


    [ https://hibernate.onjira.com/browse/HHH-1097?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45914#comment-45914 ] 

Tom Coogan commented on HHH-1097:
---------------------------------

The proposed solution appears to have been implemented in the commit for HHH-4443:

https://github.com/hibernate/hibernate-orm/commit/9e76e1b184bce54f94f744228b43f97b77312b9b

> No way to access directly access UserType in Interceptor
> --------------------------------------------------------
>
>                 Key: HHH-1097
>                 URL: https://hibernate.onjira.com/browse/HHH-1097
>             Project: Hibernate ORM
>          Issue Type: Improvement
>    Affects Versions: 3.1 rc 1
>         Environment: 3.1rc1, DB2 400, JDK 1.4.2_09
>            Reporter: James Schopp
>            Priority: Minor
>
> In my custom Interceptor, I cannot access my custom UserType directly. This also has the result that the only way to determine if a field is of my UserType is by doing a string comparison: if would prefer to do "instanceof" sing this looks nice and runs faster. More detail:
> The methods of interface  "Interceptor" receive an array of interface "Type".
> For any properties/columns that are mapped using a UserType, the "type" received in the Interceptor method is actually a "CustomType" object that wraps (delegation) the UserType and implements the "Type" interface. There is no way to actually access the underlying UserType (that I know is there!)
> Finally, since there is no way to access the UserType, the only way to determine what "type" is really under all those layers is by doing types[i].getName() and then doing a string comparison against MyUserType.getClass().getName(). This is very ugly, and quite slow compared to the "instanceof" that I would like to do instead.
> And finally again, the REASON that I need to access my UserType in my Interceptor is so that the Interceptor can call an "interface" method on my UserType, and my UserType will go off an do a specific action (depending on whether it really represents a String, or Date, etc...) Currently, I must have a huge if-else-if-else block based on String comparisons that dispatch method calls depending on the type detected. The cleaner way would be to see if the type is an instance of "my" interface, and if so, call an interface method on it.
> Possible Solution
> =================
> Just add a new method to org.hibernate.type.CustomType which is/would be:
>        public UserType getUserType() { return userType; }
> Then from the Interceptor, you could do:
> if (types[i] instanceof CustomType) {
>   CustomType ct = (CustomType) types[i];
>   if (ct.getUserType instanceof MyOwnUserType) {
>      .......
>   }
> }

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list