Why is method DefaultLoadEventListener.loadFromDatasource now private?


Hi there,

I’m currently working on the Hibernate migration to 5.3.x. I’ve just discovered that org.hibernate.event.internal.DefaultLoadEventListener#loadFromDatasource is now private instead of protected as I’ve hooked in here to solve some inheritance joining issues that come with our core design. Is there a specific reason why the visibility has been restricted?

Best regards,


It most likely is a simple refactor based on the fact that DefaultLoadEventListener is an internal class and we don’t expect users to override such a class in the way that you described typically.

Can you elaborate on your inheritance join issue so we can determine if there is a better approach?


Hi there,
sorry for the delay, I was sick the last week.

Basically we have a big “Base” table that a large number of classes inherit from, using joined inheritance. The Base table includes the database identifier and the qualified class name). When I simply want to query a Base entity by using the ID, I cannot do this on MySQL/MariaDB due to the 61 table join issue. This means that I always have to prequery the Base table to get the correct class by ID, then I can query the proper ID/class combination.

For a better understanding, I have attached the existing implementation I used in Hibernate 4.3, skipping some helper methods:

	protected Object loadFromDatasource(LoadEvent event, EntityPersister persister, EntityKey keyToLoad, LoadType options) {

		String classToCheck = event.getEntityClassName();
		if (preloadProperClassToPreventTableLimit(classToCheck)) {
			// bypassing 61 table limit
			String newClassName = lookupClass(event);
			LOGGER.debug("Change {} to {} for ID {}", classToCheck, newClassName, event.getEntityId());
			EventSource source = event.getSession();
			// regenerate entity key with proper class
			persister = source.getFactory().getEntityPersister(newClassName);
			keyToLoad = source.generateEntityKey(event.getEntityId(), persister);
		return super.loadFromDatasource(event, persister, keyToLoad, options);

If you can help me with better approach (yes, I know that the design approach with inheritance was wrong in the first place, but we have to stick to this), I’d be very grateful.



You can also use a custom EntityPersister and override the load method to use your custom load logic:

public Object load(
		Serializable id,
		Object optionalObject,
		LockOptions lockOptions,
		SharedSessionContractImplementor session
	) throws HibernateException {
		return load(id, optionalObject, lockOptions.getLockMode(), session);

Then, at the base class entity level, you declare the custom persister:

@Entity(name = "BaseEntity")
@Persister( impl = MySQLCustomEntityPersister.class )
public class BaseEntity {


Thank very much for this suggestion, this looks like a more fine-grained and suitable approach which will supersede my solution.


One small question remains open: is @Persister effectively inherited to subclasses?


I don’t recall this. You should test it and see if it works. If it does not, just add @Persister to subclasses too.


All right, I will post the results when I can spare some time to implement the changes. Thanks for the help!