Using hibernate annotation with jBPM
tibocu Mar 22, 2006 7:49 AMHi,
I just spend a few houres to figure how to use Hibernate Annotaiton with jBPM.
Here is the "receipt" (can probably be improved):
1-- Create an implementation of the db persistence service:
---------------------------------------------------------------------
package com.btc.fwk.jbpm;
[Cut imports]
public class PersistenceService extends DbPersistenceServiceFactory {
private static final Log _log = LogFactory.getLog(PersistenceService.class);
private Configuration _configuration;
public PersistenceService() {
super();
_log.info("Creating Persistence Service");
}
public synchronized Configuration getConfiguration() {
_log.info("Creating AnnotationConfiguration");
if (_configuration == null) {
String hibernateCfgXmlResource = null;
if (JbpmConfiguration.Configs
.hasObject("resource.hibernate.cfg.xml")) {
hibernateCfgXmlResource = JbpmConfiguration.Configs
.getString("resource.hibernate.cfg.xml");
}
String hibernatePropertiesResource = null;
if (JbpmConfiguration.Configs.hasObject("resource.hibernate.properties")) {
hibernatePropertiesResource = JbpmConfiguration.Configs.getString("resource.hibernate.properties");
}
_configuration = new AnnotationConfiguration();
_log.info("XML configuration file = " + hibernateCfgXmlResource);
_log.info("Resource file = " + hibernatePropertiesResource);
_configuration.configure(hibernateCfgXmlResource);
if( hibernatePropertiesResource != null ) {
_log.debug("Setting Persistence hibernate properties from " + hibernatePropertiesResource);
Properties properties = new Properties();
InputStream is = null;
try {
is = PersistenceService.class.getClassLoader().getResourceAsStream(hibernatePropertiesResource);
properties.load(is);
} catch(Exception e) {
_log.error(e);
_log.debug("Hibernate properties " + hibernatePropertiesResource + " not found");
} finally {
if( is != null )
try {
is.close();
} catch (IOException e) {
_log.error(e);
}
}
_configuration.setProperties(properties);
}
}
return _configuration;
}
}
2-- Declare the service
---------------------------
In jbpm.cfg.xml:
<jbpm-context>
<!--
-->
3-- Declare the annotated classes
-----------------------------------------
Declare the annotated classes into the hibernate.cfg.xml file.
Hope this help
Thibault Cuvillier
http://www.btcweb.com