1

大多数或所有核心 hibernate 配置属性都可以在启动属性文件中指定,作为在 hibernate.cfg.xml 中指定映射的替代方法。

有没有一种简单的方法可以在属性文件中指定带注释的类的映射?

您可以在hibernate.cfg.xml配置中像这样映射带注释的类:

<session-factory>
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        ...
        <mapping class="com.annotated.classes.EntityOne"/>
</session-factory>

可以使用属性文件编写类似的配置,即hibernate.properties

hibernate.connection.driver_class = com.mysql.jdbc.Driver
hibernate.mapping = ???

如果可能的话,我还没有弄清楚如何使用属性配置指定带注释的类(实体)的映射。

4

1 回答 1

3

I don't think there is any way to specify entities in the properties file.

I suppose you could create your own custom initialization code using Configuration to accomplish what you are looking for. The problem with using a properties file, though, is that you cannot specify a property with a list of values unless you identify a way to split the value into a list. You would then need to write code that parses the value accordingly.

于 2012-05-02T23:23:30.890 回答