I found it necessary to get a connection from a Spring JpaRepository in order to see if we can use a SQL Server specific query for some tests. We need to jump through some hoops in order to get there though.
First step is to get the EntityManager (note this method requires the ReflectiontestUtils).
Next Step is to use the EntityManager's unwrap method along with Spring's SessionFactoryUtils to get the DataSource:
And with a datasource we can grab the connection (in this example I'm looking at the DB name):
how to use it with eclipselink instead of hibernate
ReplyDelete