Getting sql connection via EclipseLink

Deadly 提交于 2019-12-12 03:46:15

问题


I am trying to obtain a reference to sql connection as mentioned in the following question :

Getting a JDBC connection from EclipseLink

Here is the actual code: Connection con = entityManager.unwrap(Connection.class); This is also mentioned in EclipseLink documentation.

I keep getting following error from EclipseIDE:

The method unwrap(Class<Connection>) is undefined for the type EntityManager

1 Quickfix Add cast to 'entityManager'

If I apply the quickfix suggested by Eclipse, the code looks like this:

Connection con = ((java.sql.Wrapper) entityManager).unwrap(Connection.class);

Now, the code compiles and I can deploy my application but as soon the method is called, following error occurs:

 java.lang.ClassCastException: com.sun.proxy.$Proxy427 cannot be cast to java.sql.Wrapper

How can I solve this problem. I have an entityManager instance and using it, I want to get the dbname, db url and db schema verion

来源:https://stackoverflow.com/questions/40549872/getting-sql-connection-via-eclipselink

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!