Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select in SAP HANA + Hibernate throws error: `Method unwrap of com.sap.db.jdbc.CallableStatementSapDBFinalize is not supported`

I have the following table:

CREATE column TABLE banks (
  sk tinyint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
  code varchar(10) DEFAULT NULL,
  name varchar(100) DEFAULT NULL,
  version smallint DEFAULT NULL,
  PRIMARY KEY (sk)
);

I try to select the rows of the table with the following code (in Scala):

import scala.collection.JavaConverters._

object Test extends App {

    val session = HibernateUtil.sessionFactory.openSession        
    val q = session.createQuery("from BankHib ") 
    val list2 = q.list   // <-- code breaks here

    session.close
 }

With the following entity definition:

@Entity
@Table(name = "banks")
class BankHib {

    @Id
    var sk: Int = _

    var code: String = _
    var name: String = _
    var version: Int = _
}

And the utility to get the session factory:

object HibernateUtil {

  val sessionFactory = buildSessionFactory

    def buildSessionFactory = {
        try {
                new Configuration().configure().buildSessionFactory();
        } catch {case ex:Throwable => 
            println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    def shutdown  {
        sessionFactory.close
    } 
}

When I run the Test object I get the following exception:

Caused by: com.sap.db.jdbc.exceptions.SQLFeatureNotSupportedExceptionSapDB: Method unwrap of com.sap.db.jdbc.CallableStatementSapDBFinalize is not supported.
    at com.sap.db.jdbc.exceptions.SQLExceptionSapDB._createException(SQLExceptionSapDB.java:155)
    at com.sap.db.jdbc.exceptions.SQLExceptionSapDB.generateSQLException(SQLExceptionSapDB.java:26)
    at com.sap.db.jdbc.WrapperDummy.unwrap(WrapperDummy.java:25)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:64)
    ... 26 more

What is the problem and how to fix it? what is the feature that is not supported?

like image 497
ps0604 Avatar asked Jul 23 '17 13:07

ps0604


1 Answers

The exception start from a hibernate code that has been modified recently.

The linked issue is this one : https://hibernate.atlassian.net/browse/HHH-10256

The change is on hibernate 5.2.8. So if you are on a 5.2.8+ version (apparently the error you gave point to a 5.2.10 version), can you try to downgrade to 5.2.7 ?

I'm worried because very old sap drivers seems to be ok with the old code. If newer hana driver have issue with newer code, it will be hard to find the correct match between hibernate version and sap driver version.

If you have exception with 5.2.7 and 5.2.10, you will have to reopen the hibernate issue.

And also you have support from SAP for hana (if you use hana, you already pay for that) so contact them to have a better driver that support JDBC correctly. They will probably don't even answer ( you pay a product, it is not to tell them there is bug, the bug is always on your side ) but who know.

like image 131
wargre Avatar answered Sep 29 '22 14:09

wargre