Hello all,
I am having trouble using inheritance (TABLE_PER_CLASS) with Derby. Primitive types work fine, however, problems appear when I add a persistent array of primitive values to the subclass. Schema creation works OK, as does saving new values. However, when I try to run queries on the superclass I get the following error:
Code:
SEVERE: Types 'INTEGER' and 'VARCHAR () FOR BIT DATA' are not UNION compatible.
I am using Hibernate 3.5.0 (embedded). and can confirm that the problem occurs with both Derby versions I have tested with (10.2.2.0 and 10.6.1.0). Code to reproduce the problem is below:
Code:
@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public class SuperClass {
@Id
@GeneratedValue(strategy=GenerationType.TABLE)
int id;
}
Code:
@Entity
public class SubClass extends SuperClass {
@Basic
double[] doubles;
public SubClass()
{
doubles = new double[] {1, 2, 3, 4, 5};
}
public double[] getDoubles()
{
return doubles;
}
}
Code:
public class InheritanceTest
{
public static void main(String[] args)
{
// Create session factory
AnnotationConfiguration config = new AnnotationConfiguration();
config.setProperty(
"hibernate.dialect",
"org.hibernate.dialect.DerbyDialect");
config.setProperty(
"hibernate.connection.driver_class",
"org.apache.derby.jdbc.EmbeddedDriver");
config.setProperty(
"hibernate.connection.url",
"jdbc:derby:db;create=true");
config.setProperty(
"hibernate.hbm2ddl.auto",
"create-drop");
config.addAnnotatedClass(SuperClass.class);
config.addAnnotatedClass(SubClass.class);
SessionFactory sessionFactory = config.buildSessionFactory();
// Save instance of subclass
Session session = sessionFactory.openSession();
try {
SubClass subClass = new SubClass();
session.save(subClass);
session.flush();
}
finally {
session.close();
}
// Query superclass
session = sessionFactory.openSession();
try {
Query query = session.createQuery("from SuperClass");
SubClass subClass = (SubClass) query.list().get(0);
System.out.println(Arrays.toString(subClass.getDoubles()));
}
finally {
session.close();
}
}
}
Output is below:
Code:
Sep 2, 2010 10:15:37 AM org.hibernate.cfg.annotations.Version <clinit>
INFO: Hibernate Annotations 3.5.0-Final
Sep 2, 2010 10:15:37 AM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.5.0-Final
Sep 2, 2010 10:15:37 AM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Sep 2, 2010 10:15:37 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : javassist
Sep 2, 2010 10:15:37 AM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Sep 2, 2010 10:15:37 AM org.hibernate.annotations.common.Version <clinit>
INFO: Hibernate Commons Annotations 3.2.0.Final
Sep 2, 2010 10:15:38 AM org.hibernate.cfg.search.HibernateSearchEventListenerRegister enableHibernateSearch
INFO: Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
Sep 2, 2010 10:15:38 AM org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: inheritancetest.SuperClass
Sep 2, 2010 10:15:38 AM org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity inheritancetest.SuperClass on table SuperClass
Sep 2, 2010 10:15:38 AM org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: inheritancetest.SubClass
Sep 2, 2010 10:15:38 AM org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity inheritancetest.SubClass on table SubClass
Sep 2, 2010 10:15:38 AM org.hibernate.cfg.AnnotationConfiguration applyHibernateValidatorLegacyConstraintsOnDDL
INFO: Hibernate Validator not found: ignoring
Sep 2, 2010 10:15:38 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
Sep 2, 2010 10:15:38 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
Sep 2, 2010 10:15:38 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
Sep 2, 2010 10:15:38 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: org.apache.derby.jdbc.EmbeddedDriver at URL: jdbc:derby:db;create=true
Sep 2, 2010 10:15:38 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {}
Sep 2, 2010 10:15:39 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: Apache Derby, version: 10.6.1.0 - (938214)
Sep 2, 2010 10:15:39 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: Apache Derby Embedded JDBC Driver, version: 10.6.1.0 - (938214)
Sep 2, 2010 10:15:39 AM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.DerbyDialect
Sep 2, 2010 10:15:39 AM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
Sep 2, 2010 10:15:39 AM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
Sep 2, 2010 10:15:39 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Sep 2, 2010 10:15:39 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Sep 2, 2010 10:15:39 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Sep 2, 2010 10:15:39 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
Sep 2, 2010 10:15:39 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
Sep 2, 2010 10:15:39 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Sep 2, 2010 10:15:39 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
Sep 2, 2010 10:15:39 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Sep 2, 2010 10:15:39 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
Sep 2, 2010 10:15:39 AM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Sep 2, 2010 10:15:39 AM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
Sep 2, 2010 10:15:39 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Sep 2, 2010 10:15:39 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
Sep 2, 2010 10:15:39 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Sep 2, 2010 10:15:39 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Sep 2, 2010 10:15:39 AM org.hibernate.cfg.SettingsFactory createRegionFactory
INFO: Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
Sep 2, 2010 10:15:39 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Sep 2, 2010 10:15:39 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
Sep 2, 2010 10:15:39 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Sep 2, 2010 10:15:39 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Sep 2, 2010 10:15:39 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Sep 2, 2010 10:15:39 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
Sep 2, 2010 10:15:39 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Check Nullability in Core (should be disabled when Bean Validation is on): enabled
Sep 2, 2010 10:15:39 AM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Sep 2, 2010 10:15:39 AM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Sep 2, 2010 10:15:39 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: Running hbm2ddl schema export
Sep 2, 2010 10:15:39 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: exporting generated schema to database
Sep 2, 2010 10:15:39 AM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: schema export complete
Sep 2, 2010 10:15:40 AM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 20000, SQLState: 42X61
Sep 2, 2010 10:15:40 AM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Types 'INTEGER' and 'VARCHAR () FOR BIT DATA' are not UNION compatible.
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2297)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2172)
at org.hibernate.loader.Loader.list(Loader.java:2167)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:448)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1258)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at inheritancetest.InheritanceTest.main(InheritanceTest.java:50)
Caused by: java.sql.SQLSyntaxErrorException: Types 'INTEGER' and 'VARCHAR () FOR BIT DATA' are not UNION compatible.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement20.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement30.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement40.<init>(Unknown Source)
at org.apache.derby.jdbc.Driver40.newEmbedPreparedStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:534)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:452)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1596)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
at org.hibernate.loader.Loader.doList(Loader.java:2294)
... 8 more
Caused by: java.sql.SQLException: Types 'INTEGER' and 'VARCHAR () FOR BIT DATA' are not UNION compatible.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
... 28 more
Caused by: ERROR 42X61: Types 'INTEGER' and 'VARCHAR () FOR BIT DATA' are not UNION compatible.
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.sql.compile.ResultColumnList.setUnionResultExpression(Unknown Source)
at org.apache.derby.impl.sql.compile.SetOperatorNode.buildRCL(Unknown Source)
at org.apache.derby.impl.sql.compile.SetOperatorNode.bindResultColumns(Unknown Source)
at org.apache.derby.impl.sql.compile.FromSubquery.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.FromList.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.SelectNode.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.DMLStatementNode.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.DMLStatementNode.bind(Unknown Source)
at org.apache.derby.impl.sql.compile.CursorNode.bindStatement(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
... 22 more
Any suggestions for solutions/workarounds would be greatly appreciated.
Regards,
Phil