From: Stefan F. (JIRA) <no...@at...> - 2006-03-22 10:33:27
|
ClassCastException in CollectionType.toLoggableString if using CustomCollectionType ----------------------------------------------------------------------------------- Key: HHH-1586 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1586 Project: Hibernate3 Type: Bug Components: core Versions: 3.1.2, 3.1.3 Environment: Hibernate 3.1.2, Oracle 10g Reporter: Stefan Fellner Priority: Minor When implementing a UserCollectionType and setting the log-Level to debug, in CollectionType.toLoggableString a ClassCastException is thrown. I'll put a possible bugfix here: public String toLoggableString(Object value, SessionFactoryImplementor factory) throws HibernateException { if ( value == null ) return "null"; if ( Hibernate.isInitialized( value ) ) { if ( getReturnedClass().isInstance(value) ) { List list = new ArrayList(); Type elemType = getElementType( factory ); Iterator iter = getElementsIterator( value ); while ( iter.hasNext() ) { list.add( elemType.toLoggableString( iter.next(), factory ) ); } return list.toString(); } else { // this would be my solution if (value instanceof Element) { // for DOM4J "collections" only return ( (Element) value ).asXML(); //TODO: it would be better if this was done at the higher level by Printer } else { return value.toString(); } } } else { return "<uninitialized>"; } } The main problem is that UserCollectionType Interface doesn't contain getReturnedClass() method, so getReturnedClass().isInstance(value) will fail in case of UserCollectionTypes and in the else value is casted to org.dom4j.Element, while value is an instance of the UserCollectionType, which causes ClassCastException. -- 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 |