Hi Martin Unfortunately there isn't an easy way (at least not one that I'm aware of). If you're specifying the connection info in properties in your persistence.xml file then we can retrieve those values.
If you're using a WebSphere datasource then it's trickier, all we have access to is the contents of persistence.xml so we can give you the JNDI location. Getting the database name from that URL would require delving into the WebSphere datasource code though. If you don't need the database name you can at least get the type (oracle / db2 / whatever). import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI; import org.apache.openjpa.jdbc.conf.JDBCJPAConfiguration; // first get the configuration you can do the same thing with an EntityManagerFactory instead of an EntityManager EntityManager em; // assume it's initialized normally. JDBCConfiguration conf = (JDBCConfiguration) ((OpenJPAEntityManagerSPI)em).getConfiguration(); String dbDictionary = conf.getDBDictionary(); // if you've specified a DB dictionary in persistence.xml you can get that string. // if you haven't specified the DBDictionary then OpenJPA will instantiate that one for you. You can get that object like this : Object dictionaryInstance = conf.getDBDictionaryInstance(); The returned object will be an instance of one of the OpenJPA dictionaries (DB2Dictionar / OracleDictionary / etc).. This doesn't sound exactly like what you want though. Getting the database type could be made friendlier, getting the database name might be trickier (unless it's in the DBMetaData). -mike On Thu, Jul 9, 2009 at 9:35 AM, mjdenham <[email protected]> wrote: > > Hi, > > Is there an easy way to dynamically find the database name and schema name > being used by an EntityManager at runtime? > > We are using OpenJpa 1.0.4 on Websphere and an Oracle datasource. > > We would like to make the information accessible on an application screen > because we have so many environments - dev, test, uvt, uat, integration > that > it gets confusing to know which database a tester is using. > > Thanks > Martin > -- > View this message in context: > http://n2.nabble.com/How-to-get-database-information-tp3231794p3231794.html > Sent from the OpenJPA Users mailing list archive at Nabble.com. >
