[Hibernate-JIRA] Created: (HHH-2413) Offer a way to log bound jdbc parameters in a uniform way for UserType implementors
by Baptiste MATHUS (JIRA)
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: Hibernate3
Type: Improvement
Versions: 3.2.2
Reporter: Baptiste MATHUS
Priority: Minor
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-configurat.... 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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
16 years, 3 months
[Hibernate-JIRA] Created: (HBX-1110) Support for abstract/concrete pairs of POJO generation for hbm2java
by Jeff Walker (JIRA)
Support for abstract/concrete pairs of POJO generation for hbm2java
-------------------------------------------------------------------
Key: HBX-1110
URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-1110
Project: Hibernate Tools
Issue Type: Patch
Components: ant, hbm2java, reverse-engineer
Affects Versions: 3.2.4 Beta1
Environment: Hibernate 3.3.1GA, DB2 8.2, ant 1.6.5, Java 5.0 b11, eclipse (myEclipse blue 7.0) on windows xp sp3
Reporter: Jeff Walker
Priority: Minor
Attachments: HibernateExt.patch
I wanted hbm2java to be able to produce pairs of both abstract base classes and concrete classes for each POJO when reverse engineering.
I altered the ant tasks to allow this syntax:
<hbm2java ejb3="true" jdk5="true">
<base transform="{package-name}/base/{class-name}Base"/>
<concrete transform="{package-name}/{class-name}"/>
</hbm2java>
I then extended the POJO exporter (used only when base or concrete are present). This new exporter takes the meta model and runs once for all components, and then twice for each entity. The first entity run is for the base classes. Using the meta property overrides in the exporter, I force the class to be abstract, and change the generated class name according to the "transform" attribute. I also save the name of the generated class name in a hash, mapped to the original name for use in the second phase.
Then for the second run (still inside of the exporter), I force the generated class name (again via the "transform" attribute), and have the class extend the base class that was generated in the first phase.
I also introduce two new variables into the template context: basePartOfPair and concretePartOfPair. Set to true or false for the respective phase. They default to false for when the regular exporter is used.
In the templates I forced the properties to be protected (instead of private), and turned off the property generation for the concrete class. I have code in the method (exportPersistentClass) to override these at meta properties, but that didn't work, as those properties need to be set on the property level, not the class level.
You may refer to the following forum post for more background: http://forum.hibernate.org/viewtopic.php?t=994243
Note that there is no test case for this functionality yet. I'm not sure where to put it or what to do with that, but I will keep looking at that.
--
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....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
16 years, 3 months