[jira] [Created] (OPENJPA-2696) Polymorphic query with additional order by field failed with ArgumentException

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[jira] [Created] (OPENJPA-2696) Polymorphic query with additional order by field failed with ArgumentException

JIRA jira@apache.org
Azuo Lee created OPENJPA-2696:
---------------------------------

             Summary: Polymorphic query with additional order by field failed with ArgumentException
                 Key: OPENJPA-2696
                 URL: https://issues.apache.org/jira/browse/OPENJPA-2696
             Project: OpenJPA
          Issue Type: Bug
    Affects Versions: 2.2.2
            Reporter: Azuo Lee


For the following polymorphic class definitions:
{code:title=Person.java}
@Entity
@Table(name="persons")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="discriminator", discriminatorType=DiscriminatorType.CHAR)
@DiscriminatorValue("P")
public abstract class Person {
     @Id
     public long id;

     @Basic
     public java.sql.Date birth;
}
{code}
{code:title=Male.java}
@Entity
@DiscriminatorValue("M")
public class Male extends Person {
}
{code}
{code:title=Female.java}
@Entity
@DiscriminatorValue("F")
public class Female extends Person {
}
{code}
Adds some data:
{code:title=Test.java}
Male male = new Male();
male.setId(1);
male.setBirth(new java.sql.Date(System.currentTimeMillis()));
em.persist(male);
Female female = new Female();
female.setId(2);
female.setBirth(new java.sql.Date(System.currentTimeMillis()));
em.persist(female);
{code}
The following JPQL query can be executed correctly:
{code}
em.createQuery("select p from Person as p order by p.birth desc").getResultList();
{code}

but if I add an additional order by column:
{code}
em.createQuery("select p, case when p.birth is null then 1 else 0 end as b from Person as p order by b asc, p.birth desc").getResultList();
{code}

The query failed with error:
{noformat}
Exception occurred during processing request: Cannot instantiate abstract class of type "com.test.Person" with object id "2"; this may indicate that the inheritance discriminator for the class is not configured correctly.
{noformat}
What's wrong?



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)
Loading...