开发者

hibernate, server specific configuration

开发者 https://www.devze.com 2023-03-03 17:11 出处:网络
we have two different environments (test and production), each with it\'s own database connection. The database connection is configured in the hibernate.cfg.xml, together with the mappings etc.

we have two different environments (test and production), each with it's own database connection.

The database connection is configured in the hibernate.cfg.xml, together with the mappings etc. The hibernate.cfg.xml is part of the application - hence we cannot configure the database connection depending on the environment.

So we need some kind of configuration outside the applicatio开发者_运维技巧n.

What is the best way for handling server specific database configurations with hibernate?


U can configure using annotations. below is exa

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消