1

I would like to get my DataSource properties, like user name or url. This is my persistence.xml:

<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="defaulttransaction-type="JTA">
        <jta-data-source>MyDataSource</jta-data-source>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
    </persistence-unit>
</persistence>

Inside GlassFish 4.1, I have the required JDBC Resource and JDBC ConnectionPool, respectively MyDataSource and MyDataSourceCP. If this is useful, MyDataSource is a javax.sql.ConnectionPoolDataSource and MyDataSourceCP is a oracle.jdbc.pool.OracleConnectionPoolDataSource.

MyDataSourceCP is configured with some parameters like URL, user name and password. I would like to extract those properties from Java.

So far, I have tried the following:

  1. How to get jpa datasource properties from Entity Manager
  2. How to retrieve the datasource used by a persistence unit programmatically
  3. JPA - Is there a way/method to retrieve Persistence Unit information

But with no results.

As @Stoffelchen (in (1)), I would like something like

someObject.someMethod( ).getProperties( )
// or
someObject.someMethod( ).getProperties( "username" )
// or
someObject.someMethod( ).getUserName( )

Is there a way to achieve this?

I am using Hibernate 4.3.

Thanks in advance

Community
  • 1
  • 1
MiguelKVidal
  • 1,498
  • 1
  • 15
  • 23

0 Answers0