hibernate的<class name=" " table=" " schema=" "> 中schema的问题

来源:互联网 发布:seo关键词优化软件 编辑:程序博客网 时间:2024/06/07 14:58
本人正在做spring和activiti的整合,数据库用的是MySQL,hibernate做持久化。运行项目数据库中只有activiti默认生成的表,自己在.hbm.xml中定义的表没有生成,检查了很久发现在.hbm.xml文件中多了个schema,因为是在其他文件中复制过来的,一开始没在意,问题就出在这个schema上,先贴上一段代码
<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><!-- Generated 2013-11-7 17:56:35 by Hibernate Tools 4.0.0 --><hibernate-mapping>    <class name="com.mf.ctr.corp.MfCorp" table="mf_corp" schema="acts">        <id name="pk_corp" type="string">            <column name="pk_corp" length="32" />            <generator class="uuid" />        </id>        <property name="dr" type="java.lang.Long">            <column name="DR" precision="10" scale="0" />        </property>        <property name="pk_pcorp" type="string">            <column name="pk_pcorp" length="32" />        </property>        <property name="unitcode" type="string">            <column name="unitcode" length="20" />        </property>    </class></hibernate-mapping>
上边代码的schema的值是acts,其实就是对应的数据库的名称,如果在同一个数据的连接下没有acts这个数据库,就不能生成在.hbm.xml中定义的表。还有一种情况,在同一个数据连接下,如果有两个数据库acts和stca,在dataSource配置的数据库是acts而在.hbm.xml中的schema指定的是stca,这样activiti默认表会在acts中而自己定义的表则在stca中,这就将了两个不同类别的数据表放在两个数据库中,同时也有利于数据的访问安全。
0 0
原创粉丝点击