Hi everyone,
In my migration project (4.3.10 still) I’m using custom wrappers for some of the datastructures in Hibernate, such as Bag, Set etc. This is done in order to track the objects (implements Trackable). My problem is that they are not being used while running the tests, and it fails due to this. (The tests uses the normal persistentSet etc instead)
From what I’ve understood, the binding to these objects is done in the HbmBinder-class. I’ve modified this to wrap the objects to make them have the extra functionality. However, the HbmBinder.bindRoot-method is never being called due to the extendsQueue is null:
private int processExtendsQueue() {
LOG.debug("Processing extends queue");
int added = 0;
ExtendsQueueEntry extendsQueueEntry = findPossibleExtends(); // trying to get an entry from the queue
while (extendsQueueEntry != null) {
metadataSourceQueue.processHbmXml(extendsQueueEntry.getMetadataXml(), extendsQueueEntry.getEntityNames());
extendsQueueEntry = findPossibleExtends();
}
if (extendsQueue.size() > 0) {
Iterator iterator = extendsQueue.keySet().iterator();
StringBuilder buf = new StringBuilder("Following super classes referenced in extends not found: ");
while (iterator.hasNext()) {
final ExtendsQueueEntry entry = (ExtendsQueueEntry) iterator.next();
buf.append(entry.getExplicitName());
if (entry.getMappingPackage() != null) {
buf.append("[").append(entry.getMappingPackage()).append("]");
}
if (iterator.hasNext()) {
buf.append(",");
}
}
throw new MappingException(buf.toString());
}
return added;
}
@Override
protected ExtendsQueueEntry findPossibleExtends() {
Iterator<ExtendsQueueEntry> itr = extendsQueue.keySet().iterator();
while (itr.hasNext()) {
final ExtendsQueueEntry entry = itr.next();
boolean found = getClassMapping(entry.getExplicitName()) != null || getClassMapping(
AutofetchHbmBinder.getClassName(entry.getExplicitName(), entry.getMappingPackage())) != null;
if (found) {
itr.remove();
return entry;
}
}
return null;
}
The only place where something is added this extendsQueue is in the HbmBinder itself, which means that the extendsQueue initially is empty, it will never have any content:
public static void bindRoot(XmlDocument metadataXml, Mappings mappings, java.util.Map inheritedMetas,
java.util.Set<String> entityNames) throws MappingException {
final Document doc = metadataXml.getDocumentTree();
final Element hibernateMappingElement = doc.getRootElement();
java.util.List<String> names = AutofetchHbmBinder.getExtendsNeeded(metadataXml, mappings);
if (!names.isEmpty()) {
// classes mentioned in extends not available - so put it in queue
Attribute packageAttribute = hibernateMappingElement.attribute("package");
String packageName = packageAttribute == null ? null : packageAttribute.getValue();
for (String name : names) {
mappings.addToExtendsQueue(new ExtendsQueueEntry(name, packageName, metadataXml, entityNames));
}
return;
}
...
Am I misunderstanding something here? Any ideas what I should look for in order to make sure that my own custom classes gets used?
Update:
I realize now that it could be due to that in the original version, hbm was the intended way to supply the mapping, but now I instead use annotations. Could this be the reason why the creation of the wrappers does not work? If so, what class in hibernate nowadays handles the creation of the different datastructures, in the same manner as the HbmBinder handles it in the case of hbm-mapping?