Is there possible way to know which database server is use in JPA, programmatically? I think, there is a way, otherwise, JPA cannot transform JPQL
to native query
at runtime. My program also need to know DB Server Type
. Is there any function for that feature?
I use eclipseLink
& jpa 2.0
My expected program is :
EntityManagerFactory emf = Persistence.createEntityManagerFactory("JPA");
String dbPlatform = emf.getDBPlatform();
System.out.println(dbPlatform);
Output :
Oracle
MySql
MSSql
DB2
....
I never needed it, but I think the way to go is to get the JDBC connection and find in its properties that piece of information. In particular getClientInfo() and getMetaData() might be interesting.
This could be implementation specific, but as you said you use EclipseLink, you can use the following:
java.sql.Connection connection = entityManager.unwrap(java.sql.Connection.class);
Reference from here.
PS: I think you want to solve an intersting problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With