jBPM5.4-04:应用MySql数据库
jBPM5.4-04:使用MySql数据库
3.修改task-service/resources/META-INF/persistence.xml
1.下载MySql驱动放在安装目录/db/drivers/下。这里将名字修改为mysql.jar。
在MySql数据库中创建task和jbpm数据库。
2.修改db/jbpm-persistence-JPA2.xml和task-persistence-JPA2.xml,修改方式类似
将 <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" /> 或 <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/> 修改为 <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
附:
Hibernate SQL Dialects (hibernate.dialect
)
DB2 | org.hibernate.dialect.DB2Dialect |
DB2 AS/400 | org.hibernate.dialect.DB2400Dialect |
DB2 OS390 | org.hibernate.dialect.DB2390Dialect |
PostgreSQL | org.hibernate.dialect.PostgreSQLDialect |
MySQL |
org.hibernate.dialect.MySQL5Dialect |
MySQL with InnoDB | org.hibernate.dialect.MySQLInnoDBDialect |
MySQL with MyISAM | org.hibernate.dialect.MySQLMyISAMDialect |
Oracle (any version) | org.hibernate.dialect.OracleDialect |
Oracle 9i | org.hibernate.dialect.Oracle9iDialect |
Oracle 10g | org.hibernate.dialect.Oracle10gDialect |
Sybase | org.hibernate.dialect.SybaseDialect |
Sybase Anywhere | org.hibernate.dialect.SybaseAnywhereDialect |
Microsoft SQL Server | org.hibernate.dialect.SQLServerDialect |
SAP DB | org.hibernate.dialect.SAPDBDialect |
Informix | org.hibernate.dialect.InformixDialect |
HypersonicSQL | org.hibernate.dialect.HSQLDialect |
Ingres | org.hibernate.dialect.IngresDialect |
Progress | org.hibernate.dialect.ProgressDialect |
Mckoi SQL | org.hibernate.dialect.MckoiDialect |
Interbase | org.hibernate.dialect.InterbaseDialect |
Pointbase | org.hibernate.dialect.PointbaseDialect |
FrontBase | org.hibernate.dialect.FrontbaseDialect |
Firebird | org.hibernate.dialect.FirebirdDialect |
将 <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/> <property name="hibernate.connection.driver_class" value="org.h2.Driver"/> <property name="hibernate.connection.url" value="jdbc:h2:tcp://localhost/runtime/task" /> <property name="hibernate.connection.username" value="sa"/> <property name="hibernate.connection.password" value=""/> <property name="hibernate.connection.autocommit" value="false" /> <property name="hibernate.max_fetch_depth" value="3"/> <property name="hibernate.hbm2ddl.auto" value="create" /> <property name="hibernate.show_sql" value="false" /> </properties> 修改为 <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/> <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/> <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/task" /> <property name="hibernate.connection.username" value="用户名"/> <property name="hibernate.connection.password" value="密码"/> <property name="hibernate.connection.autocommit" value="false" /> <property name="hibernate.max_fetch_depth" value="3"/> <property name="hibernate.hbm2ddl.auto" value="create" /> <property name="hibernate.show_sql" value="false" /> </properties>
4.修改db/mysql_module.xml中jar的名称为mysql.jar,与db/drivers中的jar名称对应。
<resources> <resource-root path="mysql.jar"/> </resources>
5.使用的是Jboss7,修改安装目录下的standalone.xml
将 <subsystem xmlns="urn:jboss:domain:datasources:1.0"> <datasources> <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true"> <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url> <driver>h2</driver> <security> <user-name>sa</user-name> <password>sa</password> </security> </datasource> <datasource jta="true" jndi-name="java:jboss/datasources/jbpmDS" pool-name="H2DS" enabled="true" use-java-context="true" use-ccm="true"> <connection-url>jdbc:h2:~/jbpm</connection-url> <driver>h2</driver> <pool> <min-pool-size>1</min-pool-size> <max-pool-size>4</max-pool-size> <prefill>false</prefill> <use-strict-min>false</use-strict-min> <flush-strategy>FailingConnectionOnly</flush-strategy> </pool> <security> <user-name>sa</user-name> </security> <validation> <check-valid-connection-sql>SELECT 1</check-valid-connection-sql> <validate-on-match>false</validate-on-match> <background-validation>false</background-validation> </validation> </datasource> <drivers> <driver name="h2" module="com.h2database.h2"> <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class> </driver> </drivers> </datasources> </subsystem> 修改为 <subsystem xmlns="urn:jboss:domain:datasources:1.0"> <datasources> <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true"> <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url> <driver>h2</driver> <security> <user-name>sa</user-name> <password>sa</password> </security> </datasource> <datasource jta="true" jndi-name="java:jboss/datasources/jbpmDS" pool-name="H2DS" enabled="true" use-java-context="true" use-ccm="true"> <connection-url>jdbc:mysql://localhost:3306/jbpm</connection-url> <driver>mysql</driver> <pool> <min-pool-size>1</min-pool-size> <max-pool-size>4</max-pool-size> <prefill>false</prefill> <use-strict-min>false</use-strict-min> <flush-strategy>FailingConnectionOnly</flush-strategy> </pool> <security> <user-name>用户名</user-name> <password>密码</password> </security> <validation> <check-valid-connection-sql>SELECT 1</check-valid-connection-sql> <validate-on-match>false</validate-on-match> <background-validation>false</background-validation> </validation> </datasource> <drivers> <driver name="mysql" module="com.mysql"> <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class> </driver> </drivers> </datasources> </subsystem>
6.修改安装目录下的build.properties,将数据库的配置从H2,改为MySql
# default is H2 #db.name=h2 #db.driver.jar.name=${db.name}.jar #db.driver.download.url=http://repo1.maven.org/maven2/com/h2database/h2/${H2.version}/h2-${H2.version}.jar #other options are mysql db.name=mysql db.driver.module.prefix=com/mysql db.driver.jar.name=${db.name}.jar db.driver.download.url=https://repository.jboss.org/nexus/service/local/repositories/central/content/mysql/mysql-connector-java/5.1.18/mysql-connector-java-5.1.18.jar
7.修改/lib/jbpm-human-task-war-5.4.0.Final-EE6.war/WEB-INF/classes/META-INF/persistence.xml文件中的hibernate.dialect
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
8.修改/lib/jbpm-gwt-console-server-5.4.0.Final-EE6.war/WEB-INF/classes/META-INF/persistence.xml文件中的hibernate.dialect和hibernate.hbm2ddl.auto。
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" /> <property name="hibernate.hbm2ddl.auto" value="create" />
9.修改build.xml
在 <java classname="org.jbpm.DemoTaskService" fork="true"> <classpath> <pathelement path="${install.home}/task-service/target"/> <path refid="classpath.human.task" /> </classpath> </java> 中加 <sysproperty key="jbpm.user.group.mapping" value="file:///F:/PDF/jbpm/jbpm-installer/jboss-as-7.1.1.Final/standalone/configuration/roles.properties"/> 变为 <java classname="org.jbpm.DemoTaskService" fork="true"> <sysproperty key="jbpm.user.group.mapping" value="file:///F:/PDF/jbpm/jbpm-installer/jboss-as-7.1.1.Final/standalone/configuration/roles.properties"/> <classpath> <pathelement path="${install.home}/task-service/target"/> <path refid="classpath.human.task" /> </classpath> </java> 根据你的实际目录修改
10.在CMD中到你的安装目录下,运行
ant install.demo 或 ant install.demo.noeclipse
11.运行
ant start.human.task创建task数据库表 ,创建完成后按Ctrl+C,再按退出创建。
12.运行
ant start.jboss启动,会创建jbpm数据库表。
启动成功后再运行
ant stop.jboss成功关闭后修改安装目录下\jboss-as-7.1.1.Final\standalone\deployments\jbpm-gwt-console-server.war\WEB-INF/classes/META-INF/persistence.xml文件中的hibernate.hbm2ddl.auto。
<property name="hibernate.hbm2ddl.auto" value="update" />