2016-06-23 178 views
0

我使用Wildfly8和postgresql作为我的数据库。我需要org.postgresql.PGConnection才能实现postgresql的LISTEN/NOTIFY功能。连接抛出异常蜻蜓

我的代码如下所示:

private Connection conn; 
private org.postgresql.PGConnection pgconn; 
Conn = entityManager.unwrap(java.sql.Connection.class); 
this.pgconn = conn.unwrap(org.postgresql.PGConnection.class); 

我获得以下异常:

java.sql.SQLException: Not a wrapper for: org.postgresql.PGConnection

什么可这里的问题?

+0

在康涅狄格州印刷的价值,我得到: :[email protected] –

回答

0

在这种情况下,您的第一个Connection实例可能是代理对象。如果你正在使用Wildfly你必须这样做:

((WrappedConnection)conn).getUnderlyingConnection().unwrap(PgConnection.class); 

而且必须在jboss-部署,structure.xml这样的声明:

<?xml version="1.0" encoding="UTF-8"?> 
<jboss-deployment-structure> 
    <deployment> 
     <dependencies> 
      <module name="org.jboss.ironjacamar.jdbcadapters" /> 
      <module name="org.postgresql" /> 
     </dependencies> 
    </deployment> 
</jboss-deployment-structure>