91

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

jmattheis
  • 10,494
  • 11
  • 46
  • 58
GiriByaks
  • 941
  • 1
  • 7
  • 6

18 Answers18

81

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
Narayan Yerrabachu
  • 1,714
  • 1
  • 19
  • 31
  • 1
    Which java version did you try this with? Intellij is unable to find this property. – comiventor Dec 06 '17 at 08:53
  • We tried with eclipse as well as Intellij. In both cases its working.Actually, we tired with java 6, 7,8 and its working without any problem for us. Just debug your code or cross check your code. – Narayan Yerrabachu Dec 06 '17 at 15:42
67

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
jpkroehling
  • 13,881
  • 1
  • 37
  • 39
  • 3
    Thanks Partenon. I am aware of the option to disable it,but I am trying to find the reason for this exception. Any pointers? – GiriByaks Jan 04 '11 at 13:55
  • 6
    As far as I understand it, it's not a problem with your application, Hibernate is just verifying if the DB supports some features and adjusting itself in case it doesn't. I would verify if any mapping is triggering this (like a LOB field), but it's nothing to worry about. – jpkroehling Jan 04 '11 at 14:09
  • 5
    **WARNING**: Using this solution with Oracle is **dangerous**! It leads to **unexpected COMMITs**. When hibernate creates temporary tables it has to open a new transaction, since DDL statements in Oracle DB imply COMMIT. By setting this option to false you disable opening new transaction and DDL get issues within your transaction COMMITing it. – Boris Brodski Apr 04 '14 at 14:22
  • @BorisBrodski , are you sure the behavior you described is caused by setting this property to false? Looking at the code, I don't see anything extra being executed when this is false: https://github.com/hibernate/hibernate-orm/blob/f19c8e995a763fe7c31fbb7f5777ac6ff608c215/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentInitiator.java#L76 . – jpkroehling Apr 07 '14 at 14:59
  • 3
    @jpkrohling Yes, I debugged hibernate4.2.7 and saw if myself: Setting `useJdbcMetadata` to `false` prevents `metaReportsDDLCausesTxnCommit` to be set and it stays `false`! http://grepcode.com/file/repo1.maven.org/maven2/org.hibernate/hibernate-core/4.1.2.Final/org/hibernate/engine/jdbc/internal/JdbcServicesImpl.java – Boris Brodski Apr 07 '14 at 15:43
  • Works fine. Put this line on file persistence.xml – Thiago Pereira May 21 '15 at 14:01
28

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.

Steve K
  • 19,408
  • 6
  • 52
  • 50
  • 5
    Does it mean that `Driver does not support LOB feature` or `Database does not support LOB feature` ? – Marek Sebera May 15 '12 at 09:55
  • @MarekSebera Driver. I'm having this problem because something is mysteriously overriding my C3P0 library with an ancient version. The database supports it just fine. – Nyerguds Nov 23 '15 at 12:10
24

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
Vlad Dinulescu
  • 1,173
  • 1
  • 14
  • 24
21

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>
UdayKiran Pulipati
  • 6,579
  • 7
  • 67
  • 92
15

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.

Torsten Krah
  • 368
  • 3
  • 9
10

Just add below line in application.properties

spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults: false
slfan
  • 8,950
  • 115
  • 65
  • 78
Rupesh Patil
  • 153
  • 3
  • 9
10

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.

Jacek Prucia
  • 1,026
  • 2
  • 12
  • 22
4

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.

Boris Brodski
  • 8,425
  • 4
  • 40
  • 55
4

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.

kettunen
  • 111
  • 7
3

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
1

The problem occurs because of you didn't choose the appropriate JDBC. Just download and use the JDBC for oracle 10g rather than 11g.

sami
  • 358
  • 1
  • 4
  • 5
  • Huh. This completely contradicts the response of Boris Brodski. You sure this makes any difference? – Nyerguds Nov 23 '15 at 13:05
1

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

S K
  • 11
  • 1
0

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.

peterong
  • 93
  • 3
0

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

Shailesh Chandra
  • 2,164
  • 2
  • 17
  • 25
0

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

FranKs
  • 51
  • 4
-1

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

-3

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

logixplayer
  • 939
  • 2
  • 13
  • 23