【问题标题】:hibernate, server specific configuration休眠,服务器特定配置
【发布时间】:2011-08-21 12:34:58
【问题描述】:

我们有两个不同的环境(测试和生产),每个都有自己的数据库连接。

数据库连接在 hibernate.cfg.xml 中配置,以及映射等。 hibernate.cfg.xml 是应用程序的一部分 - 因此我们无法根据环境配置数据库连接。

所以我们需要在应用程序之外进行某种配置。

使用 hibernate 处理特定于服务器的数据库配置的最佳方法是什么?

【问题讨论】:

    标签: database hibernate configuration connection


    【解决方案1】:

    您可以使用注释进行配置。下面是例子

    sessionFactory = new AnnotationConfiguration()
                        .addPackage("test.animals") //the fully qualified package name
                        .addAnnotatedClass(Flight.class)
                        .addAnnotatedClass(Sky.class)
                        .addAnnotatedClass(Person.class)
                        .addAnnotatedClass(Dog.class)
                        .addResource("test/animals/orm.xml")
                        .configure()
                        .buildSessionFactory();
    

    【讨论】:

    • 但是我有专门用于特定服务器的源代码。但我不喜欢在我的源代码中有特定于服务器的配置。我想到了一个外部配置,它不是应用程序的一部分
    猜你喜欢
    • 1970-01-01
    • 2010-11-08
    • 2017-03-31
    • 1970-01-01
    • 2018-09-19
    • 1970-01-01
    • 2015-07-28
    • 2016-05-06
    • 2018-10-21
    相关资源
    最近更新 更多