禁用上下文 LOB 创建,因为 createClob() 方法引发错误

发布于 2024-10-10 08:08:05 字数 339 浏览 3 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(18

我家小可爱 2024-10-17 08:08:05

通过添加下面的属性来禁用此警告。

对于 Spring 应用程序:

spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false

普通 JPA:

hibernate.temp.use_jdbc_metadata_defaults=false

Disable this warning by adding property below.

For Spring application:

spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false

Normal JPA:

hibernate.temp.use_jdbc_metadata_defaults=false
柠栀 2024-10-17 08:08:05

正如您所注意到的,这个异常并不是真正的问题。它发生在启动期间,当 Hibernate 尝试从数据库检索一些元信息时。如果这让您烦恼,您可以禁用它:

hibernate.temp.use_jdbc_metadata_defaults false

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:

hibernate.temp.use_jdbc_metadata_defaults false
乖乖公主 2024-10-17 08:08:05

查看 来源

基本上我们只是检查
我们是否可以调用
LOB 的 java.sql.Connection 方法
JDBC 4 中添加了创建。我们不仅
检查java.sql.Connection是否存在
声明了这些方法,而且还
是否是实际的java.sql.Connection
实例实现它们(即可以是
调用而不简单地抛出一个
例外)。

因此,它正在尝试确定是否可以使用一些新的 JDBC 4 方法。我猜你的驱动程序可能不支持新的 LOB 创建方法。

Looking at the comments in the source:

Basically here we are simply checking
whether we can call the
java.sql.Connection methods for LOB
creation added in JDBC 4. We not only
check whether the java.sql.Connection
declares these methods, but also
whether the actual java.sql.Connection
instance implements them (i.e. can be
called without simply throwing an
exception).

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.

挽梦忆笙歌 2024-10-17 08:08:05

为了隐藏异常:

对于 Hibernate 5.2(和 Spring Boot 2.0),您可以使用其他人指出的 use_jdbc_metadata_defaults 属性:

# Meant to hide HHH000424: Disabling contextual LOB creation as createClob() method threw error 
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults: false

或者,如果您不想从上面的设置(有一条评论警告我们一些Oracle副作用,我不知道它是否有效),你可以像这样禁用异常的日志记录:

logging:
   level: 
      # Hides HHH000424: Disabling contextual LOB creation as createClob() method threw error 
      org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl: WARN

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:

# Meant to hide HHH000424: Disabling contextual LOB creation as createClob() method threw error 
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults: false

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:

logging:
   level: 
      # Hides HHH000424: Disabling contextual LOB creation as createClob() method threw error 
      org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl: WARN
浅浅 2024-10-17 08:08:05

摆脱异常

INFO - HHH000424: Disabling contextual LOB creation as createClob() method threw error :java.lang.reflect.InvocationTargetException

hibernate.cfg.xml 文件中添加以下属性

<property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>

To get rid of the exception

INFO - HHH000424: Disabling contextual LOB creation as createClob() method threw error :java.lang.reflect.InvocationTargetException

In hibernate.cfg.xml file Add below property

<property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>
此刻的回忆 2024-10-17 08:08:05

使用 Hibernate 4.3.x / 5.0.x 对此进行更新 - 您只需将此属性设置为 true:

<prop key="hibernate.jdbc.lob.non_contextual_creation">true</prop>

即可消除该错误消息。效果相同,但没有“抛出异常”细节。
有关详细信息,请参阅 LobCreatorBuilder 源代码。

Update to this for using Hibernate 4.3.x / 5.0.x - you could just set this property to true:

<prop key="hibernate.jdbc.lob.non_contextual_creation">true</prop>

to get rid of that error message. Same effect but without the "threw exception" detail.
See LobCreatorBuilder source for details.

娇柔作态 2024-10-17 08:08:05

正如其他评论中提到的,使用

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.

ら栖息 2024-10-17 08:08:05

只需在 application.properties 中添加以下行

spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults: false

Just add below line in application.properties

spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults: false
隔岸观火 2024-10-17 08:08:05

将 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.

﹎☆浅夏丿初晴 2024-10-17 08:08:05

如果你设置:

hibernate.temp.use_jdbc_metadata_defaults: false

当你的表名包含像 user 这样的保留字时,它可能会给你带来 PostgreSQL 的麻烦。插入后,它将尝试使用以下命令查找 id 序列:

select currval('"user"_id_seq');

这显然会失败。至少在 Hibernate 5.2.13 和 Spring Boot 2.0.0.RC1 中是这样。尚未找到其他方法来阻止此消息,因此现在忽略它。

If you set:

hibernate.temp.use_jdbc_metadata_defaults: false

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:

select currval('"user"_id_seq');

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.

淑女气质 2024-10-17 08:08:05

使用 Spring boot 2.1.x 时,启动应用程序时会出现此警告消息。

如此处所示,也许这个问题在早期版本中没有出现,因为相关属性默认设置为 true 而现在为 false:

https://github.com/spring-projects/spring-boot/issues/12007

因此,解决这个问题就像添加以下属性一样简单spring application.property 文件。

spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation = true

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.

spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation = true
随波逐流 2024-10-17 08:08:05

出现此问题是因为您没有选择合适的 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.

绮烟 2024-10-17 08:08:05

我正在使用 hibernate 5.3.17,通过添加给定属性它可以正常工作

hibernate.default_entity_mode=dynamic-map
hibernate.temp.use_jdbc_metadata_defaults=true
hibernate.jdbc.lob.non_contextual_creation = true

谢谢

I am using hibernate 5.3.17 and it works fine by adding given properties

hibernate.default_entity_mode=dynamic-map
hibernate.temp.use_jdbc_metadata_defaults=true
hibernate.jdbc.lob.non_contextual_creation = true

Thanks

铃予 2024-10-17 08:08:05

当我的 Web 应用程序由访问权限不足的登录用户在 Linux 中启动时,我遇到了此错误。这个错误

org.hibernate.engine.jdbc.internal.LobCreatorBuilder - HHH000424:
禁用上下文 LOB 创建,因为 createClob() 方法引发错误:
java.lang.reflect.InitationTargetException

通常前面有其他错误/异常,尤其是来自应用程序服务器的错误/异常
对于雄猫:

org.apache.catalina.LifecycleException:无法初始化组件...

java.lang.UnsatisfiedLinkError:...无法打开共享对象文件:没有这样的文件或目录

解决方案:

  1. 停止您的 Web 应用程序当前实例。

  2. 使用超级用户或具有足够访问权限的用户(即 root)登录

  3. 程序

I hit this error when my web app was started in Linux by user logged in with insufficient access rights. This error

org.hibernate.engine.jdbc.internal.LobCreatorBuilder - HHH000424:
Disabling contextual LOB creation as createClob() method threw error :
java.lang.reflect.InvocationTargetException

usually preceded by other errors / exceptions, especially from your application server i.e
for Tomcat:

org.apache.catalina.LifecycleException: Failed to initialize component ...

or

java.lang.UnsatisfiedLinkError: ... cannot open shared object file: No such file or directory

Solution:

  1. Stop your web apps current instance.

  2. Login with super user or those with sufficient access rights i.e root

  3. Restart your web app or call previous function again.

当爱已成负担 2024-10-17 08:08:05

对于任何在 Spring Boot 2 中遇到此问题的人

默认情况下 Spring Boot 使用的是 hibernate 5.3.x 版本,我在 pom.xml 中添加了以下属性

<hibernate.version>5.4.2.Final</hibernate.version>

,并且错误消失了。错误原因已经在上面的帖子中解释了

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

<hibernate.version>5.4.2.Final</hibernate.version>

and error was gone. Reason for error is already explained in posts above

近箐 2024-10-17 08:08:05

正如 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..

浪菊怪哟 2024-10-17 08:08:05

如果将 @Temporal 注释与 java.sql.* 类一起使用,请删除它。

Remove @Temporal annotations if you use it with java.sql.* classes.

爱你不解释 2024-10-17 08:08:05

检查您是否没有使用 VPN。我遇到了同样的问题,但意识到我正在连接到远程的数据库!

Check if you are not on a VPN. I had the same issue but realized the db I was connecting to remote!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文