Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » How to get DataSource Name from entity manager
icon5.gif  How to get DataSource Name from entity manager [message #671731] Wed, 18 May 2011 19:54 Go to next message
NeoZ  is currently offline NeoZ
Messages: 9
Registered: May 2011
Junior Member
I just started using jpa/eclipselink and I have a question:
I am using JTA data source and I know I can do the following to get a JDBC connection:

dataSource = (DataSource) (new InitialContext()).lookup("dataSourceName");
connection = dataSource.getConnection();

My question is: if I don't want to hard code the dataSourceName and I want to retrieve it from my code, how to I achieve this? Is there a method like:

entityManger.getDataSourceName()?

thanks



Re: How to get DataSource Name from entity manager [message #671941 is a reply to message #671731] Thu, 19 May 2011 12:01 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

You can get the JDBC connection from an EntityManager using,

em.unwrap(java.sql.Connection.class)


James : Wiki : Book : Blog : Twitter
Re: How to get DataSource Name from entity manager [message #671982 is a reply to message #671941] Thu, 19 May 2011 14:07 Go to previous messageGo to next message
NeoZ  is currently offline NeoZ
Messages: 9
Registered: May 2011
Junior Member
Thanks James. I tried that and it didn't work. It always return a null value.
Re: How to get DataSource Name from entity manager [message #673738 is a reply to message #671982] Tue, 24 May 2011 15:21 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

What version are you using?

Ensure you are in a transaction.


James : Wiki : Book : Blog : Twitter
Re: How to get DataSource Name from entity manager [message #674316 is a reply to message #673738] Thu, 26 May 2011 13:47 Go to previous messageGo to next message
NeoZ  is currently offline NeoZ
Messages: 9
Registered: May 2011
Junior Member
James wrote on Tue, 24 May 2011 11:21
What version are you using?

Ensure you are in a transaction.

i am using eclipselinke 2.2. transaction-type="JTA"
I created an entity facade so that i don't have to manage transaction manually.
Re: How to get DataSource Name from entity manager [message #675181 is a reply to message #674316] Mon, 30 May 2011 14:10 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Ensure a JTA transaction is active when you call the API.


James : Wiki : Book : Blog : Twitter
Previous Topic:Eclipselink cache coordination throwing NoClassDefFoundError
Next Topic:Progress/Openedge database
Goto Forum:
  


Current Time: Mon Sep 22 04:18:31 GMT 2014

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

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