-->
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.  [ 5 posts ] 
Author Message
 Post subject: Inheritance problem with Derby
PostPosted: Thu Sep 02, 2010 5:52 am 
Newbie

Joined: Thu Sep 02, 2010 5:27 am
Posts: 3
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


Top
 Profile  
 
 Post subject: Re: Inheritance problem with Derby
PostPosted: Thu Sep 02, 2010 7:04 am 
Regular
Regular

Joined: Thu May 07, 2009 5:56 am
Posts: 94
Location: Toulouse, France
it seems the same problem here: viewtopic.php?f=1&t=1002668

can you post the sql generated by Hibernate, please? (hibernate.show_sql=true)

_________________
everything should be made as simple as possible, but not simpler (AE)


Top
 Profile  
 
 Post subject: Re: Inheritance problem with Derby
PostPosted: Thu Sep 02, 2010 9:54 am 
Newbie

Joined: Thu Sep 02, 2010 5:27 am
Posts: 3
Hi hallmit,

the relevant output snippet is below:

Code:
INFO: schema export complete
Hibernate: insert into SubClass (doubles, id) values (?, ?)
Hibernate: select superclass0_.id as id0_, superclass0_.doubles as doubles1_, superclass0_.clazz_ as clazz_ from ( select id, nullif(0,0) as doubles, 0 as clazz_ from SuperClass union all select id, doubles, 1 as clazz_ from SubClass ) superclass0_
Sep 2, 2010 2:43:46 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 20000, SQLState: 42X61
Sep 2, 2010 2:43:46 PM 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


Regards,
Phil


Top
 Profile  
 
 Post subject: Re: Inheritance problem with Derby
PostPosted: Thu Sep 02, 2010 10:19 am 
Regular
Regular

Joined: Thu May 07, 2009 5:56 am
Posts: 94
Location: Toulouse, France
ok, i was getting the same error times ago but with DB2...take a look at http://opensource.atlassian.com/project ... e/HHH-2507 (Andreas Münch found a workarounds for Derby, last comment)

the pseudo column 'nullif(0,0) as doubles' returns as type an INTEGER and the column 'doubles' has type VARCHAR () FOR BIT DATA. the union of these columns doesn't work (this is a Hibernate bug). provide your own dialect to circumvent the Derby dialect bug.

_________________
everything should be made as simple as possible, but not simpler (AE)


Top
 Profile  
 
 Post subject: Re: Inheritance problem with Derby
PostPosted: Thu Sep 02, 2010 10:50 am 
Newbie

Joined: Thu Sep 02, 2010 5:27 am
Posts: 3
Thank you very much hallmit. Using the snippet that Andreas posted I was able to get my code working.

In InheritanceTest, I added a custom dialect as a static class:

Code:
public class InheritanceTest
{
   public static class CustomDerbyDialect extends DerbyDialect
   {
      @Override
      public String getSelectClauseNullString(int p_sqlType)
      {
         return "CAST(NULL AS " + getTypeName(p_sqlType, 1, 1, 1) + ")";
      }
   }


Then set this class as the dialect:

Code:
AnnotationConfiguration config = new AnnotationConfiguration();
config.setProperty(
    "hibernate.dialect",
    CustomDerbyDialect.class.getName());


I also voted for the bug in JIRA. Thanks again.

Regards,
Phil


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.