How to call bindRoot-method from my own HbmBinder-class in the processHbmXml-method?

Hi everyone,

I have a bit of a problem that I need some input on. I’m migrating a Hibernate tool from version 3.2 to the newest release. However, I also need a version for Hibernate 4.3.10 for another project. The tool extends or copies most of the classes in Hibernate to add extra functionality. The problem is that in version 4.3.10 the HbmBinder-class is called in a different method.

In 3.5 it was like this:

 protected void add(org.dom4j.Document doc) throws MappingException {
	 HbmBinder.bindRoot(doc, createMappings(),
	 CollectionHelper.EMPTY_MAP);
	 }

And in Hibernate 4.3.10 it is like this:

private void processHbmXml(XmlDocument metadataXml, Set<String> entityNames) {
			try {
				HbmBinder.bindRoot( metadataXml, createMappings(), CollectionHelper.EMPTY_MAP, entityNames );
			}
			catch ( MappingException me ) {
				throw new InvalidMappingException(
						metadataXml.getOrigin().getType(),
						metadataXml.getOrigin().getName(), 
						me
				);
			}
	for ( String entityName : entityNames ) {
				if ( annotatedClassesByEntityNameMap.containsKey( entityName ) ) {
					annotatedClasses.remove( annotatedClassesByEntityNameMap.get( entityName ) );
					annotatedClassesByEntityNameMap.remove( entityName );
				}
			}
		}

What I want to accomplish is something like this:

@Override
private void processHbmXml(XmlDocument metadataXml, Set<String> entityNames) {
			try {
				AutofetchHbmBinder.bindRoot( metadataXml, createMappings(), CollectionHelper.EMPTY_MAP, entityNames );
			}
			catch ( MappingException me ) {
				throw new InvalidMappingException(
						metadataXml.getOrigin().getType(),
						metadataXml.getOrigin().getName(), 
						me
				);
			}
	for ( String entityName : entityNames ) {
				if ( annotatedClassesByEntityNameMap.containsKey( entityName ) ) {
					annotatedClasses.remove( annotatedClassesByEntityNameMap.get( entityName ) );
					annotatedClassesByEntityNameMap.remove( entityName );
				}
			}
		}

Since the tool that I’m migrating uses a different HbmBinder, I need to change the bindRoot-call to that specific class. The problem is that the new method is private so I can’t override it. Does anyone have an idea what I could do to solve this?

Hibernate 3.x is no longer supported. You won’t even find that class in Hibernate 5.x.

Since this might have been an internal class, it might be that the release notes won’t help you too much. Better migrate it to a later version since not all Hibernate developers have worked on 3.x.

1 Like

Thanks for the answer Vlad. Yes it’s probably wise to simply move to a newer version and not spend time fixing something that probably will be changed anyway. In this case, would you recommend me to move to a 4.x or 5.x release? The goal is to have both 4.x and 5.x versions available, but I thought originally that it would be easier to take the migration step by step.

Go for 5.x since some issues are going to be backported on 5.1 or 5.2.

The 4.x branches are too old and is no longeer maintained

1 Like

Alright so you’re right about that class doesn’t exist in Hibernate 5.x, but since one the projects that I’m going to evaluate the method uses Hibernate 4.3.10, this problem still persists. Is there any way around this?

Best thing to do is to get the 4.x branch and check out the source code. In 5.x, we have:

  • MappingBinder for HBM
  • AnnotationBinder for JPA and Hibernate annotations

It might be that MappingBinder and RootEntitySourceImpl are close to the previous mechanism for parsing xML mappings.

You mean simply comparing 4.x to 5.x and see if I can use 5.x:s method of parsing the XML mappings? By the way, I have some other similar questions regarding for example how to set up the EventListeners properly when the logic has been changed radically since 3.2 (was done in the Configuration-class), should I open up separate threads here on the forum for each question? I don’t want to bloat it too much.

By the way Vlad, you’ve earned yourself a mention in my thesis report as the Hibernate Expert. :wink:

1 Like

Thanks for the mention.

I guess we can split all the questions into multiple threads so that it will be easier for others to follow a certain solution.

1 Like