开发者

How to work with 2 RDBMS in a project

开发者 https://www.devze.com 2023-03-07 15:20 出处:网络
I\'m working with an java-web using MySQL RDBMS and I\'m using Hibernate as an ORM in my project. Now I upgrade my app to work both on web and on Android, so I\'m tending to use 开发者_如何学CSQLite

I'm working with an java-web using MySQL RDBMS and I'm using Hibernate as an ORM in my project.

Now I upgrade my app to work both on web and on Android, so I'm tending to use 开发者_如何学CSQLite to manipulate data on Android.

I found the jars to make Hibernate work with SQLite but I cant find out how to make my class use the hibernate.cfg.xml in src.android.dao package instead of the hibernate.cfg.xml in src package.

If I don't misunderstand something in Hibernate document, they say that you can work with multi RDBMS at one project. Then, please tell me how to do it. My English is bad, so, if I misunderstood, then please confirm that for me (Hibernate cant work with 2 RDBMS in one project) .

Many thanks!


Assuming "src" really is part of the package, this should work:

URL config = ClassLoader.getSystemResource("/src/android/dao/hibernate.cfg.xml");
Configuration c = new Configuration();
c.configure(config);

You can have multiple different hibernate configuration files in a project. What they probably meant by supporting multiple databases in the same project is the ability to target them for support, rather than using them simultaneously.


If I'm not mistaken, you would need to do:

configuration.configure("/android/dao/hibernate.cfg.xml");

Instead of:

configuration.configure();
0

精彩评论

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