My database uses MySQL and I'm using hibernate as an ORM framework. I have one instance where I need to access the MySQL Connection
object. I use the following code to get a java.sql.Connection
object:
getHibernateTemplate().getSessionFactory().getCurrentSession().connection();
However, when I try to cast it to a (com.mysql.jdbc.Connection
) object, I get the following exception:
java.lang.ClassCastException: $Proxy50 cannot be cast to com.mysql.jdbc.Connection
Strangely, if I do conn.getClass().getName()
, the class type returned is '$Proxy50' and not 'java.sql.Connection' or some other meaningful type.
What is the correct method for obtaining a vendor specific Connection
object from Hibernate? (I'm trying to read a MySQL system property). Why does my above example not work?