-
1. Re: EJB application with multiple database support
welle Nov 19, 2010 7:36 AM (in response to philani)I'm not sure what your question is, but as long as you using Hibernate standard to access the database and no "native" SQL by yourself the database dialect setup in the Hibernate config should do the trick if you want to swtich database provider.
-
2. Re: EJB application with multiple database support
philani Nov 19, 2010 7:37 AM (in response to welle)Thats the problem, there will be native SQL. SQL optimized for Oracle might no run on MS SQL.
-
3. Re: EJB application with multiple database support
welle Nov 19, 2010 7:40 AM (in response to philani)Well, then you have to make your own solution with some kind of externalization of your SQL statements (perhaps in a property file) that you need to update for each supported database provider.
-
4. Re: EJB application with multiple database support
welle Nov 19, 2010 7:48 AM (in response to welle)Perhaps Hibernate named queries can help. (I'm not sure if they support native SQL statements though)
-
5. Re: EJB application with multiple database support
philani Nov 19, 2010 7:47 AM (in response to welle)This might be a dum question....using Hibernate entity manager, is there a way to interrogate what the underlying datase is?
-
6. Re: EJB application with multiple database support
welle Nov 19, 2010 8:25 AM (in response to philani)Opps... my mind was totally set on Hibernate standalone. You are talking about the Entity Manager and JPA. I would use the "createnamedQuery" method in the EntityManager.
I don't know how to find out the underlaying database, but surely it must be possible. At least it must be possible to find out the dialect settings from the Hibernate setup, anyone? -
7. Re: EJB application with multiple database support
welle Nov 19, 2010 8:51 AM (in response to welle)I believe you can do the following:
org.hibernate.SessionFactory sessionFactory = ((org.hibernate.ejb.EntityManagerImpl) enityManager).getSession().getSessionFactory();
org.hibernate.impl.Dialect dialect = ((SessionFactoryImpl) sessionFactory).getDialect();
...but I haven't tested it...
-
8. Re: EJB application with multiple database support
philani Nov 19, 2010 8:53 AM (in response to welle)Thanks Anders, will give it a try