Remove quotes from table name in queries on IBMi


Our IBMi doesn’t like table names wrapped in quotes. Is there a way to remove the quotes from the table name? Example:

Hibernate: select t1_0.codigo,t1_0.descricao,t1_0.englobamento from "i#shared.tiporend" t1_0 where t1_0.codigo=?

This query generates an error on the IBMi side.

Also, if we do not specify the dialect on persistence.xml, the selected dialect is DB2Dialect, which prompts the db version warning.

[org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 118) HHH000511: The 7.4.0 version for [org.hibernate.dialect.DB2Dialect] is no longer supported, hence certain features may not work properly. The minimum supported version is 10.5.0. Check the community dialects project for available legacy versions.

But since we are on IBMi the version is in fact v7r4

However, if we specify manually the DB2iDialect (which does not prompt the db version error), we get the following error:

Caused by: java.lang.NullPointerException: Cannot invoke "String.isEmpty()" because "rowId" is null
        at org.hibernate@6.2.13.Final//org.hibernate.dialect.DB2iDialect.rowId(
        at org.hibernate@6.2.13.Final//org.hibernate.dialect.Dialect.registerColumnTypes(
        at org.hibernate@6.2.13.Final//org.hibernate.dialect.DB2Dialect.registerColumnTypes(
        at org.hibernate@6.2.13.Final//org.hibernate.dialect.Dialect.contributeTypes(
        at org.hibernate@6.2.13.Final//org.hibernate.dialect.DB2Dialect.contributeTypes(
        at org.hibernate@6.2.13.Final//org.hibernate.dialect.Dialect.contribute(
        at org.hibernate@6.2.13.Final//org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(
        at org.hibernate@6.2.13.Final//org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(
        at org.hibernate@6.2.13.Final//org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(
        at org.hibernate@6.2.13.Final//
        at org.hibernate.jipijapa-hibernate6@30.0.0.Final//
        ... 10 more

We are currently testing on Wildfly 30 (Hibernate 6.2.13).

On our Wildfly 15 (Hibernate 5.3.7) installation everything works just fine with the defaults.

This NPE was fixed with [HHH-17344] - Hibernate JIRA in Hibernate ORM 6.4. You will have to upgrade if you want this fix. Also, note that DB2 for iSeries is not “really” supported. We try to provide a best effort support because it’s an IBM product, but we do not have any means to test against that database, so whenever DB2 for iSeries deviates from DB2 for LUW behavior, there will be problems.

I don’t know why the quoting with " doesn’t work in your case. According to the documentation, this is the proper way to quote identifiers that contain special characters like a #.

Maybe your @Table mapping is wrong. You have to separate the schema/catalog name from table name e.g. @Table(name = "tiporend", schema = "i#shared")

Thank you for your reply, and your team efforts on supporting IBMi. Your @Table mapping suggestion results in the following query string:

[select t1_0.codigo,t1_0.descricao,t1_0.englobamento from "i#shared".tiporend t1_0 where t1_0.codigo=?]

The db server still complains. Even on IBMi system console, using interactive query, the quoted names are not accepted. I’ll try to investigate on this matter.

However I was able to apparently circumvent que issue by extending the DB2Dialect and overriding quoteOpen and quoteClose methods. I’ll keep testing and adding more complex queries and operations to see how the library handles them.

1 Like