[hibernate-issues] [Hibernate-JIRA] Resolved: (HHH-2490) ClassCastException causes a logging statement to throw another ClassCastException upon inconsistent instantiation of NullableType
Diego Pires Plentz (JIRA)
noreply at atlassian.com
Sun Sep 23 10:37:14 EDT 2007
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2490?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Diego Pires Plentz resolved HHH-2490.
-------------------------------------
Assignee: Diego Pires Plentz
Resolution: Duplicate
> ClassCastException causes a logging statement to throw another ClassCastException upon inconsistent instantiation of NullableType
> ---------------------------------------------------------------------------------------------------------------------------------
>
> Key: HHH-2490
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2490
> Project: Hibernate3
> Issue Type: Bug
> Components: core
> Affects Versions: 3.2.2
> Environment: MS SQLServer
> Windows 2000
> Java 1.5.0_10
> Reporter: Øyvind Roth
> Assignee: Diego Pires Plentz
>
> (Have me excused that I don't know well the internalities of Hibernate,
> but I think that you get the point from some kind of "bird's perpective" anyhow).
> My pojo is defined in my xml mapping with a column/field as follows:
> ...
> <property name="encrypted"
> type="string"
> column="encrypted"
> insert="true"
> update="true"
> not-null="true"/>
> ...
> The corresponding POJO class is defined with two access methods:
> String getEncrypted();
> and
> boolean isEncrypted();
> The field is a String with possible values "f" or "t".
> Of convenience reasons I have added a parallell method
> operating on boolean. My database is designed with a CHAR(1)
> for booleans. (All this because the dam... RDBMS standard doesn't
> advice a consistent boolean data type, a really big blunder from
> time back in System R. OT ok, but I got it out.)
> When Hibernate parses my instantiated pojo, a Boolean instance is
> generated. But it's "repository" is prepared with a StringType as a
> consequence of my XML configuration file. During the course, the
> method nullSafeSet of class NullableType is called with the value
> parameter Boolean. Eventually the
> "public abstract String toString(Object value) throws HibernateException;"
> method is called for StringType, which is implemented with a simple typecast.
> Exception received. Whether this behavior is ok or not is one discussion.
> But there's a second problem to it also: When the exception is received,
> NullableType tries to log the event:
> ...
> catch ( RuntimeException re ) {
> log().info( "could not bind value '" + nullSafeToString( value ) + "' to parameter: " + index + "; " + re.getMessage() );
> throw re;
> }
> ...
> And the same shit happens again. So the developer does not receive the actual exception,
> but the exception received from the logging statement. A strong golden rule of thumb:
> A logging statement should never ever throw. This is what I would call a bug in Hibernate.
> Setting the log level to ERROR will of course not solve the problem,
> because the string paramater is evaluated before the log statement is ever reached.
> A variant of this issue is described under: "HHH-2034"
--
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