-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Hibernate 5.2.2 Oracle 12.1 ORA-17004 Struct null Value
PostPosted: Tue Nov 29, 2016 6:15 am 
Newbie

Joined: Tue Nov 29, 2016 5:33 am
Posts: 2
Use case:
Convert Java-Object into Struct-Object and save it into Oracle Database.
For this I annotated the Geometry-Property in the bean with @Convert and wrote the needed Converter-Class.
It works perfectly with not-null-Values. Reading and writing.

Problem:
It does NOT work with null-Values.
The error message, the Oracle Database gives is
Quote:
ORA-17004 Invalid column type
But the Type-Id is the correct for this Database-Column. And it worked with not-null-Values, right?
With a bit of debugging I think, I found the Problem. Probably it lies in the class org.hibernate.type.descriptor.sql.BasicBinder in Line 61, where the Database-Call is
Code:
st.setNull( index, sqlDescriptor.getSqlType() );

This is always called from Hibernate, when the value is null. But according to Oracle Documentation the right call for this should be
Code:
st.setNull(index, sqlDescriptor.getSqlType(), sql_type_name) );

At least, if you save Values of type REF, ARRAY, or STRUCT.

Question:
Is there a workarround for this problem? Or is there a fix for the BasicBinder-Class? Or am I missing something here?


Top
 Profile  
 
 Post subject: Re: Hibernate 5.2.2 Oracle 12.1 ORA-17004 Struct null Value
PostPosted: Tue Nov 29, 2016 11:36 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
AttributeConverters are less flexible than Hibernate Types.

You have two options here:

1. Either you declare your own Hibernate type as explained in this article. The SqlTypeDescriptor gives you access to the underlying PreparedStatement so you can call the setNull variant you want.

2. You can implement a UserType, as explained in the official User Guide, and again you get access to the JDBC PreparedStatement.

The former option is probably the best one because it makes a clear separation between a Java and a SQL TypeDescriptior. UserType combines both these two responsibilities, hence it comes with a tons of methods that you need to implement.


Top
 Profile  
 
 Post subject: Re: Hibernate 5.2.2 Oracle 12.1 ORA-17004 Struct null Value
PostPosted: Wed Nov 30, 2016 3:46 am 
Newbie

Joined: Tue Nov 29, 2016 5:33 am
Posts: 2
Thank you for your fast reply. Maybe I will try option 1.

Are there any plans to fix the BasicBinder-Class on the long run? I would prefer a solution without dependencies to Hibernate. But I can live with this solution.


Top
 Profile  
 
 Post subject: Re: Hibernate 5.2.2 Oracle 12.1 ORA-17004 Struct null Value
PostPosted: Wed Nov 30, 2016 4:00 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
JPA portability is a myth. In reality, you need provider-specific features if you want to get the most out of your data access layer.

To answer your question, it's the JPA AttributeConverter who needs a fix, not the Hibernate implementation. Imagine implementing a JSON column on top of AttributeConverter. That would be almost impossible to do it properly without having access to the underlying JDBC Statement or ResultSet. Therefore, AttributeConverter is nice, but Hibernate types are awesome.

Chek out this list of features that you'll miss if you stick to strict JPA.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.