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 thehibernate.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();
精彩评论