Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom classloader for Hibernate-mapping

Does anyone know a way to intercept the call Hibernate will make to instantiate a class indicated in a .hbm.xml file? I need a way to use a custom ClassLoader to provide an instance. I don't want to change class loading for Hibernate in general, just the instantiate of the mapped "POJO" class.

<hibernate-mapping>
    <class name="com.foo.Bar" table="Bar">

In the example code above, when Hibernate wants to instantiate Bar I need to provide that class with custom code instead of relying on the default class loading behavior.

Thanks in advance for any insight,
saethi

like image 854
saethi Avatar asked Mar 04 '26 14:03

saethi


1 Answers

You can customize the way Hibernate creates entities with a custom Tuplizer. See the hibernate documentation, chapter 4.5.

You can extend PojoEntityTuplizer, and override the buildInstantiator(PersistentClass persistentClass) method by returning an Instantiator instance which builds entities however you prefer.

like image 89
Flavio Avatar answered Mar 07 '26 02:03

Flavio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!