We had a discussion with TomB about JBPM needs and one of the important requirements is to
inject existing Hibernate Session/SessionFactory.
At the moment design looks as follows:
1) The bootstrap method in IdentityStore creates HibernateEntityManagerFactory during
initialization of the store.
| protected HibernateEntityManagerFactory
bootstrapHibernateEntityManager(IdentityStoreConfigurationMetaData configurationMD) throws
IdentityException
| {
|
| String persistenceUnit =
configurationMD.getOptionSingleValue(PERSISTENCE_UNIT);
|
| if (persistenceUnit == null)
| {
| throw new IdentityException("Persistence Unit not defined for
IdentityStore: " + getId());
| }
|
| return
(HibernateEntityManagerFactory)Persistence.createEntityManagerFactory(persistenceUnit);
|
| }
|
Single instance of the IdentityStore (that reflect to one configuration piece) can be
utilized by different repositories/realms so...
2) Each time the new IdentitySession is created it calls
IdentityStore.createIdentityStoreSession() to get new IdentityStoreSession connected with
the store. Then every time different realm call the same IdentityStore instance,
IdentityStoreSession is passed to the IdentityStore methods inside IdentityStoreInvocation
object. The actuall HibernateEntityManager object is there and HibernateIdentityStoreImpl
retreives it from IdentityStoreSession context:
| protected HibernateEntityManager
getHibernateEntityManager(IdentityStoreInvocationContext ctx) throws IdentityException
| {
| try
| {
| return
(HibernateEntityManager)ctx.getIdentityStoreSession().getSessionContext();
| }
| catch (IdentityException e)
| {
| throw new IdentityException("Cannot obtain HibernateEntityManager",
e);
| }
| }
|
Currently there is no direct way to pass the existing EntityManager. Direct workaround for
now is to extend HibernateIdentityStoreImpl and override the
bootstrapHibernateEntityManager method. It could be also possible to change
IdentitySessionImpl and inject Hibernate Session object there.
Such possibility should be enabled by default so other possibilities I see are:
- Use JNDI to grab HibernateEntityManagerFactory.
- Enable other ways to bootstrap the whole framework - like MC. Then it should be easier
to inject different components
One other problem is that currently HibernateIdentityStoreImpl uses both JPA and Hibernate
annotations and therefore requires HibernateEntityManager. For projects that use plain
hibernate (SessionFactory) it may rise a problem to provide HibernateEntityManager/Factory
object. I see that hibernate EntityManagerFactoryImpl has a constructor that could be
used:
http://www.hibernate.org/hib_docs/entitymanager/api/org/hibernate/ejb/Ent...
| EntityManagerFactoryImpl(org.hibernate.SessionFactory sessionFactory,
javax.persistence.spi.PersistenceUnitTransactionType transactionType, boolean
discardOnClose, Class sessionInterceptorClass)
|
I cannot confirm it is allowed/suggested/possible way of doing the conversion.
Probably the best way to go will be to just change HibernateIdentityStoreImpl to use plain
hibernate without JPA annotations or classes.
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4206495#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...