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

**URL:** <https://discourse.hibernate.org/t/how-to-call-bindroot-method-from-my-own-hbmbinder-class-in-the-processhbmxml-method/202>\
**Category:** Hibernate ORM\
**Created:** [February 7, 2018, 1:57pm UTC](https://discourse.hibernate.org/t/how-to-call-bindroot-method-from-my-own-hbmbinder-class-in-the-processhbmxml-method/202 "2018-02-07T13:57:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![UptownErik](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/uptownerik/32/47_2.png) [@UptownErik](https://discourse.hibernate.org/u/UptownErik)\
**Post date:** [February 7, 2018, 1:57pm UTC](https://discourse.hibernate.org/t/how-to-call-bindroot-method-from-my-own-hbmbinder-class-in-the-processhbmxml-method/202/1 "2018-02-07T13:57:40Z")

</div>

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:

```auto
 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:

```auto
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:

```auto
@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?

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [February 7, 2018, 2:20pm UTC](https://discourse.hibernate.org/t/how-to-call-bindroot-method-from-my-own-hbmbinder-class-in-the-processhbmxml-method/202/2 "2018-02-07T14:20:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![UptownErik](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/uptownerik/32/47_2.png) [@UptownErik](https://discourse.hibernate.org/u/UptownErik)\
**Post date:** [February 7, 2018, 2:24pm UTC](https://discourse.hibernate.org/t/how-to-call-bindroot-method-from-my-own-hbmbinder-class-in-the-processhbmxml-method/202/3 "2018-02-07T14:24:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [February 7, 2018, 2:26pm UTC](https://discourse.hibernate.org/t/how-to-call-bindroot-method-from-my-own-hbmbinder-class-in-the-processhbmxml-method/202/4 "2018-02-07T14:26:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![UptownErik](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/uptownerik/32/47_2.png) [@UptownErik](https://discourse.hibernate.org/u/UptownErik)\
**Post date:** [February 9, 2018, 10:09am UTC](https://discourse.hibernate.org/t/how-to-call-bindroot-method-from-my-own-hbmbinder-class-in-the-processhbmxml-method/202/5 "2018-02-09T10:09:47Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [February 9, 2018, 11:12am UTC](https://discourse.hibernate.org/t/how-to-call-bindroot-method-from-my-own-hbmbinder-class-in-the-processhbmxml-method/202/6 "2018-02-09T11:12:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![UptownErik](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/uptownerik/32/47_2.png) [@UptownErik](https://discourse.hibernate.org/u/UptownErik)\
**Post date:** [February 9, 2018, 11:52am UTC](https://discourse.hibernate.org/t/how-to-call-bindroot-method-from-my-own-hbmbinder-class-in-the-processhbmxml-method/202/7 "2018-02-09T11:52:12Z")

</div>

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. 😉

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [February 9, 2018, 11:57am UTC](https://discourse.hibernate.org/t/how-to-call-bindroot-method-from-my-own-hbmbinder-class-in-the-processhbmxml-method/202/8 "2018-02-09T11:57:39Z")

</div>

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.
