0

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

Community
  • 1
  • 1
user1107888
  • 1,481
  • 5
  • 34
  • 55

0 Answers0