문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top