禁用上下文 LOB 创建,因为 createClob() 方法引发错误
我正在使用 Hibernate 3.5.6 和 Oracle 10g。我在初始化期间看到以下异常,但应用程序本身工作正常。出现这个异常的原因是什么?以及如何纠正?
异常
禁用上下文 LOB 创建,因为 createClob()
方法引发了错误:java.lang.reflect.InitationTargetException
Info
Oracle版本:Oracle数据库10g企业版版本10.2.0.4.0 JDBC驱动程序:Oracle JDBC驱动程序,版本:11.1.0.7.0
I am using Hibernate 3.5.6 with Oracle 10g. I am seeing the below exception during initialization but the application itself is working fine. What is the cause for this exception? and how it can be corrected?
Exception
Disabling contextual LOB creation as createClob()
method threw error : java.lang.reflect.InvocationTargetException
Info
Oracle version: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0
JDBC driver: Oracle JDBC driver, version: 11.1.0.7.0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(18)
通过添加下面的属性来禁用此警告。
对于 Spring 应用程序:
普通 JPA:
Disable this warning by adding property below.
For Spring application:
Normal JPA:
正如您所注意到的,这个异常并不是真正的问题。它发生在启动期间,当 Hibernate 尝试从数据库检索一些元信息时。如果这让您烦恼,您可以禁用它:
As you noticed, this exception isn't a real problem. It happens during the boot, when Hibernate tries to retrieve some meta information from the database. If this annoys you, you can disable it:
查看 来源:
因此,它正在尝试确定是否可以使用一些新的 JDBC 4 方法。我猜你的驱动程序可能不支持新的 LOB 创建方法。
Looking at the comments in the source:
So, it's trying to determine if it can use some new JDBC 4 methods. I guess your driver may not support the new LOB creation method.
为了隐藏异常:
对于 Hibernate 5.2(和 Spring Boot 2.0),您可以使用其他人指出的 use_jdbc_metadata_defaults 属性:
或者,如果您不想从上面的设置(有一条评论警告我们一些Oracle副作用,我不知道它是否有效),你可以像这样禁用异常的日志记录:
In order to hide the exception:
For Hibernate 5.2 (and Spring Boot 2.0), you can either use the use_jdbc_metadata_defaults property that the others pointed out:
Or, if you want to not have any side effects from the above setting (there's a comment warning us about some Oracle side effects, I don't know if it's valid or not), you can just disable the logging of the exception like this:
摆脱异常
在
hibernate.cfg.xml
文件中添加以下属性To get rid of the exception
In
hibernate.cfg.xml
file Add below property使用 Hibernate 4.3.x / 5.0.x 对此进行更新 - 您只需将此属性设置为 true:
即可消除该错误消息。效果相同,但没有“抛出异常”细节。
有关详细信息,请参阅 LobCreatorBuilder 源代码。
Update to this for using Hibernate 4.3.x / 5.0.x - you could just set this property to true:
to get rid of that error message. Same effect but without the "threw exception" detail.
See LobCreatorBuilder source for details.
正如其他评论中提到的,使用
hibernate.temp.use_jdbc_metadata_defaults = false
......将修复烦人的消息,但可能会导致许多其他令人惊讶的问题。更好的解决方案是禁用上下文 LOB 创建:
hibernate.jdbc.lob.non_contextual_creation = true
这将导致 Hibernate(在我的例子中是 5.3.10.Final)跳过探测 JDBC 驱动程序并仅输出以下消息:
HHH000421:禁用上下文 LOB 创建,因为 hibernate.jdbc.lob.non_contextual_creation 为 true
到目前为止,此设置似乎不会导致任何问题。
As mentioned in other comments using
hibernate.temp.use_jdbc_metadata_defaults = false
...will fix the annoying message, but can lead to many other surprising problems. Better solution is just to disable contextual LOB creation with this:
hibernate.jdbc.lob.non_contextual_creation = true
This will cause Hibernate (in my case, its 5.3.10.Final) to skip probing the JDBC driver and just output following message:
HHH000421: Disabling contextual LOB creation as hibernate.jdbc.lob.non_contextual_creation is true
So far it looks like this setting doesn't cause any problems.
只需在 application.properties 中添加以下行
Just add below line in application.properties
将 JDBC 驱动程序更新到最新版本消除了令人讨厌的错误消息。
您可以从这里下载:
http://www .oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html
不过需要免费注册。
Updating JDBC driver to the lastest version removed the nasty error message.
You can download it from here:
http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html
Free registration is required though.
如果你设置:
当你的表名包含像 user 这样的保留字时,它可能会给你带来 PostgreSQL 的麻烦。插入后,它将尝试使用以下命令查找 id 序列:
这显然会失败。至少在 Hibernate 5.2.13 和 Spring Boot 2.0.0.RC1 中是这样。尚未找到其他方法来阻止此消息,因此现在忽略它。
If you set:
it can cause you troubles with PostgreSQL when your table name contains reserved word like user. After insert it will try to find id sequence with:
which will obviously fail. This at least with Hibernate 5.2.13 and Spring Boot 2.0.0.RC1. Haven't found other way to prevent this message so now just ignoring it.
使用 Spring boot 2.1.x 时,启动应用程序时会出现此警告消息。
如此处所示,也许这个问题在早期版本中没有出现,因为相关属性默认设置为 true 而现在为 false:
https://github.com/spring-projects/spring-boot/issues/12007
因此,解决这个问题就像添加以下属性一样简单spring application.property 文件。
When working with Spring boot 2.1.x this warning message appears when starting up the application.
As indicated here, maybe this problem didn't show up in earlier versions because the related property was set to true by default and now it is false:
https://github.com/spring-projects/spring-boot/issues/12007
In consequence, solving this is as simple as adding the following property to the spring application.property file.
出现此问题是因为您没有选择合适的 JDBC。只需下载并使用适用于 Oracle 10g 而不是 11g 的 JDBC。
The problem occurs because of you didn't choose the appropriate JDBC. Just download and use the JDBC for oracle 10g rather than 11g.
我正在使用 hibernate 5.3.17,通过添加给定属性它可以正常工作
谢谢
I am using hibernate 5.3.17 and it works fine by adding given properties
Thanks
当我的 Web 应用程序由访问权限不足的登录用户在 Linux 中启动时,我遇到了此错误。这个错误
通常前面有其他错误/异常,尤其是来自应用程序服务器的错误/异常
对于雄猫:
或
解决方案:
停止您的 Web 应用程序当前实例。
使用超级用户或具有足够访问权限的用户(即 root)登录
I hit this error when my web app was started in Linux by user logged in with insufficient access rights. This error
usually preceded by other errors / exceptions, especially from your application server i.e
for Tomcat:
or
Solution:
Stop your web apps current instance.
Login with super user or those with sufficient access rights i.e root
Restart your web app or call previous function again.
对于任何在 Spring Boot 2 中遇到此问题的人,
默认情况下 Spring Boot 使用的是 hibernate 5.3.x 版本,我在 pom.xml 中添加了以下属性
,并且错误消失了。错误原因已经在上面的帖子中解释了
For anyone who is facing this problem with Spring Boot 2
by default spring boot was using hibernate 5.3.x version, I have added following property in my pom.xml
and error was gone. Reason for error is already explained in posts above
正如 Jacek Prucia 所提到的,设置 hibernate.temp.use_jdbc_metadata_defaults=false 会带来其他“令人惊讶的问题”,其中之一是批量插入将停止工作。
As mentioned by Jacek Prucia, setting the
hibernate.temp.use_jdbc_metadata_defaults=false
, will bring other "surprising problems", one of them is the batch inserts will stop working..如果将 @Temporal 注释与 java.sql.* 类一起使用,请删除它。
Remove @Temporal annotations if you use it with java.sql.* classes.
检查您是否没有使用 VPN。我遇到了同样的问题,但意识到我正在连接到远程的数据库!
Check if you are not on a VPN. I had the same issue but realized the db I was connecting to remote!