8

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?

ps0604
  • 1,227
  • 23
  • 133
  • 330
  • Is there a way you can print out the generated SQL Command by Scala ? – mac.1 Jul 26 '17 at 11:49
  • This is the sql command, the program breaks just after the sql is printed: `Hibernate: select bankhib0_.sk as sk1_0_, bankhib0_.code as code2_0_, bankhib0_.name as name3_0_, bankhib0_.version as version4_0_ from banks bankhib0_` – ps0604 Jul 26 '17 at 16:29
  • I assume not having parentheses in q.list is a typo? – mikep Aug 03 '17 at 12:42
  • in Scala you may not put parentheses in functions – ps0604 Aug 03 '17 at 16:46
  • @ps0604 Where is your createQuery function? – Ramesh Maharjan Aug 04 '17 at 02:40
  • 1
    Did you set the Hana dialect on hibernate ? Did you use the latest hana driver version ? JDBC come with interface DB editor have to implement, Your error is because SAP did not bother to implement some of them, and instead, code throw this exception. – wargre Aug 04 '17 at 17:17
  • @wagre yes, the dialect is `org.hibernate.dialect.HANAColumnStoreDialect` and I took the driver `ngdbc.jar` from the latest SAP Hana Eclipse plugin – ps0604 Aug 05 '17 at 19:25
  • @RameshMaharjan `val q = session.createQuery("from BankHib ") ` – ps0604 Aug 05 '17 at 19:25

1 Answers1

2

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.

wargre
  • 4,575
  • 1
  • 19
  • 35
  • I don't see in the link you provided an error that says that `unwrap` method is not supported by the driver – ps0604 Aug 09 '17 at 04:22
  • They made code change from this issue, that introduce the unwrap : https://github.com/hibernate/hibernate-orm/commit/3adb0d76be65a098096274f2dbd9c34fac0788f5#diff-be752f681cd90a330b5d4dbb6e242748R64 – wargre Aug 09 '17 at 05:47
  • I downgraded to 5.2.7 and there's a different error now: `org.hibernate.dialect.HANAColumnStoreDialect does not support resultsets via stored procedures`. By the way, I don't have support from SAP because I'm using the Hana Express Edition that's free – ps0604 Aug 10 '17 at 03:36