Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Need connection object used by EntityManager(Help)
Need connection object used by EntityManager [message #1012600] Thu, 21 February 2013 21:32 Go to next message
Jason Jones is currently offline Jason JonesFriend
Messages: 1
Registered: February 2013
Junior Member
I am using EclipseLink under WebLogic 12c. I need to get access to the underlying java.sql.Connection object being used by the EntityManager in an EJB. I'm not going to waste time going into the reasons for this, I know most people will think it's not necessary, but I need that connection. I found the following example at http://wiki.eclipse.org/EclipseLink/Examples/JPA/EMAPI#Getting_a_JDBC_Connection_from_an_EntityManager

entityManager.getTransaction().begin();
java.sql.Connection connection = entityManager.unwrap(java.sql.Connection.class);
...
entityManager.getTransaction().commit();

But this does not work, I get null returned from the call to entityManager.unwrap(java.sql.Connection.class);

Is there another way to get the connection?

Thanks for any help!
Re: Need connection object used by EntityManager [message #1012948 is a reply to message #1012600] Fri, 22 February 2013 14:00 Go to previous message
Russell Bateman is currently offline Russell BatemanFriend
Messages: 3798
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

On 02/22/2013 04:33 AM, Jason Jones wrote:
> I am using EclipseLink under WebLogic 12c. I need to get access to the
> underlying java.sql.Connection object being used by the EntityManager in
> an EJB. I'm not going to waste time going into the reasons for this, I
> know most people will think it's not necessary, but I need that
> connection. I found the following example at
> http://wiki.eclipse.org/EclipseLink/Examples/JPA/EMAPI#Getting_a_JDBC_Connection_from_an_EntityManager
>
> entityManager.getTransaction().begin();
> java.sql.Connection connection =
> entityManager.unwrap(java.sql.Connection.class);
> ..
> entityManager.getTransaction().commit();
>
> But this does not work, I get null returned from the call to
> entityManager.unwrap(java.sql.Connection.class);
>
> Is there another way to get the connection?
> Thanks for any help!

It appears EclipseLink is supported in and by a different forum. You
might not get much help here. Check out:

http://www.eclipse.org/forums/index.php/f/111/

and/or

http://www.eclipse.org/eclipselink/
Previous Topic:Error: java.lang.NullPointerException
Next Topic:eclipse plugin error
Goto Forum:
  


Current Time: Sat Apr 20 06:22:10 GMT 2024

Powered by FUDForum. Page generated in 0.07948 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top