简体   繁体   中英

Setting values in hbm.xml files from a properties file

Is it possible to set values in a hibernate.hbm.xml file from a properties file??

<class name="com.company.table" table="TABLE" schema="$PROP_VALUE">
    <id name="id" type="integer">
        <column name="ID"/>
        <generator class="assigned" />
    </id>
    <property name="description" type="string">
        <column name="DESC" length="100" />
    </property>
</class>

您可以在执行时根据属性文件构造hibernate.cfg文件

并不是我所知道的,但是如果您使用的是maven,则可以使用资源插件实现类似的功能

I guess you are trying keep the schema configurable. One option would be to configure this schema as a part of JDBC parameter configuration (in JDBC URL) instead of doing this in every entity definition. Please note tha this will not work if you are referring to different schemas at the same time . Not sure if this is your case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM