The question: Is there any way to get an EntityManagerFactory or EntityManager object when all you have is a java.sql.Connection object?
The explanation: We have a project specifically built to access our Oracle database. This is all pretty much legacy code and the database isn't exactly set up ORM friendly. We are trying to make any new tables and additions use Eclipselink though. The problem I am having is that this entire project was setup to pass around the connection object. So I won't have the url, username, or password for accessing the database with an EntityManagerFactory.
I have tried pulling the information from the connection with the metadata and all I can get seems to be the url and the user name. The password seems to not be there, I am assuming for security reasons.
It seems like the EntityManagerFactory and Connection are very similar objects so I was hoping to find a simple way to convert it but have only found the EM to Connection, not the Connection to EM(or EMF) and so I come seeking help, or at least a definitive no, it is not possible. Thanks!
This was answered in the comments section. So thought I'd post it as an answer for clarity and completeness. In case anyone happens by this question in the future.
"You can wrap the connection in an EMF/EM using native API, but without knowing anything about the persistence unit (defined in a persistence.xml), you won't get any value from it. You would need to create a persistence unit (with entities etc) and then load it to use your connection, though it would be better if you used a connection pool which you can pass as a property to JPA" http://onpersistence.blogspot.com/2008/04/eclipselink-and-datasources.html
Thanks Chris (from the comments.)