Pergunta

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

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top