]
Jerry Cattell commented on HHH-3273:
------------------------------------
Still exists in 3.5.5. This bug should really be fixed as it wastes a lot of time when
the NPE occurs, and there is a potential patch provided.
If you need to work around the issue with the patch, I'd recommend one small change.
Change:
{noformat}
for (Object object : session.getPersistenceContext().getCollectionsByKey().keySet()) {
{noformat}
to:
{noformat}
Set keySet = HashSet(session.getPersistenceContext().getCollectionsByKey().keySet());
for (Object object : keySet) {
{noformat}
Otherwise I've gotten some ConcurrentModificationExceptions.
One-to-Many relationship not working with custom Loader
--------------------------------------------------------
Key: HHH-3273
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3273
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.2.1, 3.2.2, 3.2.3, 3.2.4, 3.2.5, 3.2.6, 3.3.1
Environment: hibernate-3.2.6.jar
Reporter: Darren Hicks
Original Estimate: 2h
Remaining Estimate: 2h
Within the context of a One-to-Many relationship, NamedQueryCollectionInitializer
.initialize() never actually populates the PersistantBag on the parent after it calls
query.setCollectionKey( key ).setFlushMode( FlushMode.MANUAL ).list() to retrieve the
children.
This is documented in the forums here:
http://forums.hibernate.org/viewtopic.php?t=986428
Additionally, the poster has a fix posted which may solve the problem, or at least lay
out the groundwork for a solution. Here is the proposed implementation of
NamedQueryCollectionInitializer.initialize():
public void initialize(Serializable key, SessionImplementor session)
throws HibernateException {
if (log.isDebugEnabled()) {
log.debug("initializing collection: " + persister.getRole()
+ " using named query: " + queryName);
}
// TODO: is there a more elegant way than downcasting?
AbstractQueryImpl query = (AbstractQueryImpl) session
.getNamedSQLQuery(queryName);
if (query.getNamedParameters().length > 0) {
query.setParameter(query.getNamedParameters()[0], key, persister
.getKeyType());
} else {
query.setParameter(0, key, persister.getKeyType());
}
List list = query.setCollectionKey(key).setFlushMode(FlushMode.MANUAL)
.list();
// Uh, how 'bout we save the collection for later retrieval?
CollectionKey collectionKey = new CollectionKey(persister, key, session
.getEntityMode());
for (Object object : session.getPersistenceContext()
.getCollectionsByKey().keySet()) {
if (collectionKey.equals(object)) {
PersistentCollection persistentCollection = session
.getPersistenceContext().getCollection(collectionKey);
Serializable[] serializables = new Serializable[list.size()];
for (int i = 0; i < list.size(); i++) {
serializables[i] = persister.getElementType().disassemble(
list.get(i), session,
persistentCollection.getOwner());
}
persistentCollection.initializeFromCache(persister,
serializables, persistentCollection.getOwner());
persistentCollection.setSnapshot(key, persistentCollection
.getRole(), serializables);
persistentCollection.afterInitialize();
session.getPersistenceContext().getCollectionEntry(
persistentCollection).postInitialize(
persistentCollection);
}
}
}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: