I would like to know if it is possible to establish a DB connection type sql.connection using entityManager
, that is, I need to call a procedure
stored in the database, usually making a connection to the database in where previously the link, user
and password is defined, obtaining it by means of a getConexion
like the following form: Conn = DriverManager.getConnection(connection, user, password);
and declaring a variable of type CallableStatement nombreVariable = conn.prepareCall
... that procedure
can be executed in the BD, but because the user's password and address were received from persistence
, and that application was migrated to WebLogic
, everything is handled through datasource
, and connections are managed through entityManager
with < strong> EclipseLink , my question is how could transform from entity
to connection
, all in favor to modify most of the methods already made, something like:
@PersistenceContext(unitName = "rmsprd")
public void setEm(EntityManager em) {
this.em = em;
..........................
connection = this.getConexion();
CallableStatement statement = connection.prepareCall("call")
}
It should be noted that using the above procedure I throw an exception
"Uncompilable source code - Erroneous sym type:"
Does anyone have any ideas or suggestions?
Regarding NULL return of the entity manager
This way I get my persistenceUnit in my entityManager
@PersistenceContext(unitName="rd")
private EntityManager em ;
@Override
public void setEm(EntityManager em) {
this.em = em;
}
and here is my method to get the connection
@Transactional
protected Connection getConnection() throws SQLException {
logger.info("contenido de Em en GetConnection"+em);
if(em.unwrap(Connection.class) != null) {
logger.info("entre a el if CONEXION ");
logger.info("entityManager2"+this.em);
return (Connection)this.em.unwrap(Connection.class);
} else {
logger.info("entre a el else CONEXION ");
logger.info("contenido de Em en GetConnection"+em);
Map datosConexion = em.getProperties();
String url = (String)datosConexion.get("javax.persistence.jdbc.url");
String user = (String)datosConexion.get("javax.persistence.jdbc.user");
String password = (String)datosConexion.get("javax.persistence.jdbc.password");
return DriverManager.getConnection(url, user, password);
}
}
Even though the method is of a transactional type, the exception still comes back to me, in fact the EM variable is already null, to which this could be due?
persistence.xml configuration
<persistence-unit name="rmsprd" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>rmsprd</jta-data-source>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
</properties>
</persistence-unit>