-->
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.  [ 1 post ] 
Author Message
 Post subject: Troublesome bug with polymorphic query using TABLE_PER_CLASS
PostPosted: Mon Feb 15, 2010 7:10 am 
Regular
Regular

Joined: Thu May 07, 2009 5:56 am
Posts: 94
Location: Toulouse, France
Hi folks,
I found this little bug while playing with Hibernate 3.3.2 and PostgreSQL 8.3:

Very simple model to understand:
Code:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
//this entity must be queryable i.e do not use @MappedSuperclass
public class Foo
{
   @Id
   private Integer id
   //other attributes.
}

Code:
@Entity
public class SonOfFoo extends Foo
{
   private String toys;
}

Code:
@Entity
public class DaughterOfFoo extends Foo
{
   private Boolean toys;
}

when I have been executed a polymorphic query ("SELECT f FROM Foo as f"), I get this error :
Code:
Caused by: org.postgresql.util.PSQLException: ERROR: UNION types boolean and character varying cannot be matched
   at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1608)

In fact, the Hibernate uses the same alias name in union clauses for columns with different SQL type. I found these similar issues for DB2 [1] and Oracle [2].
Code:
em.createQuery("SELECT f FROM Foo as f")
Hibernate:
    select
        foo0_.id as id0_,
        foo0_.toys as toys1_,
        foo0_.toys as toys3_,
        foo0_.clazz_ as clazz_
    from
        ( select
            null::bool as toys,
            id,
            0 as clazz_
        from
            Foo
        union
        all select
            toys, <-- not good. Boolean type
            id,
            1 as clazz_
        from
            DaughterOfFoo
        union
        all select
            toys, <-- not good. Varying char type
            id,
            2 as clazz_
        from
            SonOfFoo
    ) foo0_


Apparently, the problem can circumvented by setting the column name on offending attributes (@Column(name = "son_toys")) to disambiguate them... but if you have a lot of classes to customize or must map a legacy database this problem get blocker.

What do you think? Should I report an issue about this?

--cited links
[1] viewtopic.php?f=1&t=974326
[2] viewtopic.php?f=1&t=949281

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.