今天在做报表的时候,利用Hibernate JPA 2.0需要获取数据库连接com.sql.Connection的时候获取不到,网上说用这种方式解决:

entityManager.getTransaction().begin();
java.sql.Connection connection = entityManager.unwrap(java.sql.Connection.class); // unwraps the Connection class.
...
entityManager.getTransaction().commit();
但是各种尝试,总是报出错误: Hibernate cannot unwrap interface java.sql.Connection 
 最后这种方式正确:

Connection connection = entityManager.unwrap(SessionImpl.class).connection();
这样成功获取数据库连接Connection.
 

hibernate jpa 2.0 报错Hibernate cannot unwrap interface java.sql.Connection的更多相关文章

  1. CentOS6.5 重启网络报错:Bringing up interface eth0: Error: Connection activation failed: Device not managed by NetworkManager or unavailable

    CentOS6.5 重启网络报错: Bringing up interface eth0: Error: Connection activation failed: Device not manage ...

  2. 【spring data jpa】启动报错:nested exception is java.util.NoSuchElementException

    spring boot项目中 使用spring data jpa 启动报错: org.springframework.beans.factory.UnsatisfiedDependencyExcept ...

  3. 启动Spring boot报错:nested exception is java.sql.SQLException: Field 'id' doesn't have a default value

    先看具体日志: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with n ...

  4. CloudSim4.0报错NoClassDefFoundError,Caused by: java.lang.ClassNotFoundException: org.apache.commons.math3.distribution.UniformRealDistribution

    今天下载了CloudSim 4.0的代码,运行其中自带的示例程序,结果有一部分运行错误: 原因是找不到org.apache.commons.math3.distribution.UniformReal ...

  5. [转]happybase1.0 报错:ThriftPy does not support generating module with path in protocol 'f'

    happybase1.0 报错:ThriftPy does not support generating module with path in protocol 'f' 2016-10-12 14: ...

  6. jQuery3.0+报错Uncaught TypeError: e.indexOf is not a function

    jQuery3.0+报错Uncaught TypeError: e.indexOf is not a function 使用.load()绑定事件时报错,Uncaught TypeError: e.i ...

  7. MySQL8.0报错Can't connect to MySQL server on 'localhost' (10061)的解决办法

    MySQL8.0报错Can't connect to MySQL server on 'localhost' (10061)的解决办法 事情的起因     今天课堂上要展示小组项目,需要用一个软件叫W ...

  8. Jpa自定义查询报错(Failed to convert from type [java.lang.Object[]] to type)

    Jpa自定义查询报错 问题背景 今天遇到一个奇怪的报错"Failed to convert from type [java.lang.Object[]] to type",这个报错 ...

  9. 64位linux报错Could not initialize class java.awt.image.BufferedImage

    最近碰到一个问题: 64位linux报错Could not initialize class java.awt.image.BufferedImage 在WIN平台下运行正常BufferedImage ...

随机推荐

  1. UVALive 4043 Ants

    KM   构图求最小权值匹配 保证最小的权值,所连的边一定是能够不相交的. Ants Time Limit: 3000MS   Memory Limit: Unknown   64bit IO For ...

  2. jquery之onblur事件

    onblur事件与html结合 function discountCheck(){ //var checkVal=$('input:text[name="Fee1"]').val( ...

  3. hdu4497 正整数唯一分解定理应用

    C - (例题)整数分解,计数 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65535KB    ...

  4. 命运(HDU 2571 简单动态规划)

    命运 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...

  5. uva1368 DNA Consensus String

    <tex2html_verbatim_mark> Figure 1. DNA (Deoxyribonucleic Acid) is the molecule which contains ...

  6. Unity3D TouchScript 插件教程一

    只是个人学习小记,谈不上教程,但是为了命中搜索引擎关键词,只好装逼了:),可能对于大家来说太简单了吧,网上中文教程没搜到 ,只好自己摸索了. 插件资源下载地址:https://www.assetsto ...

  7. 实现在线阅读pdf功能--php

    在网上找了很久,想要实现一个在线阅读word,pdf文件的功能,网上的资料很多,但是提到真正怎么实现的比较少.现在我来简单说明一下,我实现的过程. 我现在只能实现在线阅读pdf(将word等转换成pd ...

  8. 收集点小文,讲CGI,FASTCGI,PHP-CGI,PHP-FPM之间通透点的文章

    http://blog.csdn.net/meegomeego/article/details/36180343 http://www.opsers.org/linux-home/server/php ...

  9. 把C#程序(含多个Dll)合并打包成单一文件

    实现的方式有多种. 1 Mono 项目中有一个工具,mono的一个附属工具mkbundle.(在Xamarin未被收购开源前,它是加密的商业软件.http://www.cnblogs.com/bins ...

  10. 〔写在OS边上〕定性note

    转载:http://tieba.baidu.com/p/1273477757 0 neta 有的时候我们在读书或者看文档.——啊,原来这东西的框架就是这样而已,很直白么.有的时候我们在读代码.——于是 ...