[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2413) Offer a way to log bound jdbc parameters in a uniform way for UserType implementors

Baptiste MATHUS (JIRA) noreply at atlassian.com
Tue Dec 22 10:20:31 EST 2009


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

Baptiste MATHUS commented on HHH-2413:
--------------------------------------

I was just hit once more by this "bug" (though it's more a limitation than a bug). 

There's in fact two aspects in this limitation :
1) the logger creation : when inheriting an existing Type (say TimestampType for example). Instead of using something like "net.batmat.type=trace", I could create my logger under the org.hibernate.type.net.batmat.type category.

This way, activating org.hibernate.type would be enough to activate all parameter binding logs.

THE THING IS: the logger creation occurs in the inherited class, using the org.hibernate.type.NullableType.log(). 

*A very simple solution for this would be to modify the visibility of org.hibernate.type.NullableType.log() from private to protected.*
This way we could handle simply the logger creation in our class redefinition.

2) An common API for logging parameter binding is still missing, but I admit it needs more thoughts than the first point.
Refactor a bit the NullableType code, and relocate a part of it in the AbstractType for example, or something like that.

Cheers

> Offer a way to log bound jdbc parameters in a uniform way for UserType implementors
> -----------------------------------------------------------------------------------
>
>                 Key: HHH-2413
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2413
>             Project: Hibernate Core
>          Issue Type: Improvement
>    Affects Versions: 3.2.2
>            Reporter: Baptiste MATHUS
>            Priority: Minor
>   Original Estimate: 2 hours
>  Remaining Estimate: 2 hours
>
> At the moment, when someone implements a UserType, the bound parameters won't be displayed in not explicitly displayed via loggers. 
> For example, here is what the code of NullableType.nullSafeGet() is :
> public final void nullSafeSet(PreparedStatement st, Object value, int index)
> 	throws HibernateException, SQLException {
> 		try {
> 			if ( value == null ) {
> 				if ( IS_TRACE_ENABLED ) {
> 					log().trace( "binding null to parameter: " + index );
> 				}
> 				st.setNull( index, sqlType() );
> 			}
> 			else {
> 				if ( IS_TRACE_ENABLED ) {
> 					log().trace( "binding '" + toString( value ) + "' to parameter: " + index );
> 				}
> 				set( st, value, index );
> 			}
> 		}
> 		catch ( RuntimeException re ) {
> 			log().info( "could not bind value '" + toString( value ) + "' to parameter: " + index + "; " + re.getMessage() );
> 			throw re;
> 		}
> 		catch ( SQLException se ) {
> 			log().info( "could not bind value '" + toString( value ) + "' to parameter: " + index + "; " + se.getMessage() );
> 			throw se;
> 		}
> 	}
> IMO, it would be quite a good thing to provide some method in Hibernate, something like logBoundParameter() that would do the log like above :
> > log().trace( "binding '" + toString( value ) + "' to parameter: " + index );
> This method could then be just called by implementors so as to guaranty the display is always the same about bound parameters. 
> Even more, I think it should use a special logger, just like the org.hibernate.SQL one to display this parameters. In fact, at the moment, I feel the reference documentation is not very clear about this : see http://www.hibernate.org/hib_docs/v3/reference/en/html/session-configuration.html#log-categories. It says :
> > org.hibernate.type	Log all JDBC parameters
> But that's not completely true: it will only log bound parameters that are parameters typed with standard types coming from the org.hibernate.type package. Any custom UserType won't display anything until you:
> 1) put the right log4j line for the package where your userType is located ;
> 2) think about explicitly logging those parameter values in your custom UserType (cf. my first point).
> I'm not sure I made myself totally clear,. If so, please let me know. 
> If you think that would be worth an improvement, I'll give a look to provide a patch for this. Thanks a lot.

-- 
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