]
Darren Hicks commented on HHH-3273:
-----------------------------------
Also, the custom loader is being used by the many(child) side of the one-to-many
relationship. I'm using the @Loader annotation on the child class and it works fine
with get() and/or load(). Also, I currently see the SQL specified by the custom Loader
going out on the JDBC connection, which reinforces the thought that the current
implementation is simply incomplete.
One-to-Many relationship not working with custom Loader
--------------------------------------------------------
Key: HHH-3273
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3273
Project: Hibernate3
Issue Type: Bug
Affects Versions: 3.2.1, 3.2.2, 3.2.3, 3.2.4, 3.2.5, 3.2.6
Environment: hibernate-3.2.6.jar
Reporter: Darren Hicks
Original Estimate: 2 hours
Remaining Estimate: 2 hours
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: