[
https://issues.apache.org/jira/browse/OPENJPA-660?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Vikram Bhatia updated OPENJPA-660:
----------------------------------
Description:
If the entity has OneToMany relation and collection is declared as subclass
which uses SINGLE_TABLE inheritance strategy, it fetches all rows irrespective
of Discriminator value and throws ClassCastException.
There is entity Department (table dept) having OneToMany relation with another
entity FullTimeEmployee.
@OneToMany (mappedBy="dept", cascade=CascadeType.ALL)
private Collection<FullTimeEmployee> fullTimeEmployees;
There is abstract class Employee with
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="TYPE")
There are two entity classes FullTimeEmployee and PartTimeEmployee which
extends Employee (table emp) with Discriminator values 'F' and 'P' respectively.
Now, suppose emp table contains 2 rows of PartTimeEmployee and 2 rows of
FullTimeEmployee and if test class fetches Department object and calls
dept.getFullTimeEmployees(), it throws ClassCastException as it gets 4 rows and
doesn't use discriminator and subclass type while generating SQL query.
was:
If the entity has OneToMany relation and collection is declared as subclass
which uses SINGLE_TABLE inheritance strategy, it fetches all rows irrespective
of Discriminator value and throws ClassCastException.
There is entity Department having OneToMany relation with another entity
FullTimeEmployee.
@OneToMany (mappedBy="dept", cascade=CascadeType.ALL)
private Collection<FullTimeEmployee> fullTimeEmployees;
There is abstract class Employee with
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="TYPE")
There are two entity classes FullTimeEmployee and PartTimeEmployee which
extends Employee (table emp) with Discriminator values 'F' and 'P' respectively.
Now, Support emp table contains 2 rows of PartTimeEmployee and 2 rows of
FullTimeEmployee and if test class fetches Department object and calls
dept.getFullTimeEmployees(), it throws ClassCastException as it gets 4 rows and
doesn't use discriminator and sub class type while generating SQL query.
> ClassCastException when using OneToMany Relation and collection is subclass
> using Discriminator with SINGLE_TABLE strategy.
> ---------------------------------------------------------------------------------------------------------------------------
>
> Key: OPENJPA-660
> URL: https://issues.apache.org/jira/browse/OPENJPA-660
> Project: OpenJPA
> Issue Type: Bug
> Components: jpa
> Affects Versions: 1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.1.0, 1.1.1, 1.2.0
> Reporter: Vikram Bhatia
> Attachments: testInheritance.zip
>
>
> If the entity has OneToMany relation and collection is declared as subclass
> which uses SINGLE_TABLE inheritance strategy, it fetches all rows
> irrespective of Discriminator value and throws ClassCastException.
> There is entity Department (table dept) having OneToMany relation with
> another entity FullTimeEmployee.
> @OneToMany (mappedBy="dept", cascade=CascadeType.ALL)
> private Collection<FullTimeEmployee> fullTimeEmployees;
> There is abstract class Employee with
> @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
> @DiscriminatorColumn(name="TYPE")
> There are two entity classes FullTimeEmployee and PartTimeEmployee which
> extends Employee (table emp) with Discriminator values 'F' and 'P'
> respectively.
> Now, suppose emp table contains 2 rows of PartTimeEmployee and 2 rows of
> FullTimeEmployee and if test class fetches Department object and calls
> dept.getFullTimeEmployees(), it throws ClassCastException as it gets 4 rows
> and doesn't use discriminator and subclass type while generating SQL query.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.