From: Joe K. (JIRA) <no...@at...> - 2006-05-24 20:55:29
|
PersistentList.readFrom() Shouldn't Pad With Nulls For UserCollectionType ------------------------------------------------------------------------- Key: HHH-1782 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1782 Project: Hibernate3 Type: Bug Components: core Versions: 3.1.3 Environment: Hibernate 3.1.3, DB2 8.1.3 Reporter: Joe Kelly Priority: Minor I'm using HIbernate's UserCollectionType feature to persist a custom List implementation. The custom List's add(int, Object) and add(Object) methods do some validity checking such as making sure that the Object param is not null. Unfortunately, PersistentList.readFrom() does not deal with this case. Here is the code for that method: ------------- public Object readFrom(ResultSet rs, CollectionPersister persister, CollectionAliases descriptor, Object owner) throws HibernateException, SQLException { Object element = persister.readElement( rs, owner, descriptor.getSuffixedElementAliases(), getSession() ) ; int index = ( (Integer) persister.readIndex( rs, descriptor.getSuffixedIndexAliases(), getSession() ) ).intValue(); //pad with nulls from the current last element up to the new index for ( int i = list.size(); i<=index; i++) { list.add(i, null); } list.set(index, element); return element; } ------------- The problem is the "pad with nulls" section. When a null object is added to the underlying custom List implementation, an exception is thrown. Perhaps you could use temporary List to solve this. For example: ------------- public Object readFrom(ResultSet rs, CollectionPersister persister, CollectionAliases descriptor, Object owner) throws HibernateException, SQLException { Object element = persister.readElement( rs, owner, descriptor.getSuffixedElementAliases(), getSession() ) ; int index = ( (Integer) persister.readIndex( rs, descriptor.getSuffixedIndexAliases(), getSession() ) ).intValue(); List temp = new ArrayList(list); //pad with nulls from the current last element up to the new index for ( int i = list.size(); i<=index; i++) { temp.add(i, null); } temp.set(index, element); list.clear(); list.addAll(temp); return element; } ------------- -- 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 |