You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Łukasz Ostaniewicz (JIRA)" <ji...@apache.org> on 2010/08/13 12:13:15 UTC
[jira] Created: (OPENJPA-1766) Polymorphic queries, selecting all
childres - different result depending on select phrase
Polymorphic queries, selecting all childres - different result depending on select phrase
-----------------------------------------------------------------------------------------
Key: OPENJPA-1766
URL: https://issues.apache.org/jira/browse/OPENJPA-1766
Project: OpenJPA
Issue Type: Bug
Components: jpa
Affects Versions: 2.0.0
Environment: windows 7, jdk1.5.0_22
Reporter: Łukasz Ostaniewicz
Priority: Minor
I've got simple inheritance entity tree:
@Entity
@Table(name = "mgruchmagazynowy", schema="magazyn")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="rodzaj",discriminatorType=DiscriminatorType.INTEGER,length=1)
public class RuchMagazynowy implements Serializable {
(...)
}
@Entity
@DiscriminatorValue(value="0")
public class Dostawa extends RuchMagazynowy {
(...)
}
@Entity
@DiscriminatorValue(value="1")
public class Wydanie extends RuchMagazynowy {
}
I've got two rows in "magazyn.mgruchmagazynowy" table: one with "rodzaj" set to 0 and one with "rodzaj" set to 1
I'm trying to select all children (both Dostawa and Wydanie) and distinguish beetwen them: iterating over the results and using .getClass() or instanceof. My JUNIT test looks like:
List<Object[]> list = dao.findRM();
for (int i = 0; i < list.size(); i++) {
final Object[] row = (Object[]) list.get(i);
final Class clazz1 = row[0].getClass();
final Class clazz2 = row[1].getClass();
log.info("class1:" + clazz1);
log.info("class2:" + clazz2);
}
The problem is: I cannot achieve this if I don't specify TYPE(u) amoung SELECT items on my SELECT phrase. I thing the results of my both test cases should be equal (As I think, only test case 2 results gives correct results).
TEST CASE 1:
String select = "SELECT u,e FROM RuchMagazynowy u, ElementRuchuMagazynowego e " +
" WHERE u.id = e.ruchMagazynowy.id ";
query = em.createQuery(select);
List<Object[]> items = query.getResultList();
RESULT:
2890 [main] INFO org - class1:class pl.imedia.magazyn.bo.RuchMagazynowy
2890 [main] INFO org - class2:class pl.imedia.magazyn.bo.ElementRuchuMagazynowego
2890 [main] INFO org - class1:class pl.imedia.magazyn.bo.RuchMagazynowy
2890 [main] INFO org - class2:class pl.imedia.magazyn.bo.ElementRuchuMagazynowego
TEST CASE 2:
String select = "SELECT u,e, TYPE(u) FROM RuchMagazynowy u, ElementRuchuMagazynowego e " +
" WHERE u.id = e.ruchMagazynowy.id ";
query = em.createQuery(select);
List<Object[]> items = query.getResultList();
RESULT:
2864 [main] INFO org - class1:class pl.imedia.magazyn.bo.Dostawa
2864 [main] INFO org - class2:class pl.imedia.magazyn.bo.ElementRuchuMagazynowego
2864 [main] INFO org - class1:class pl.imedia.magazyn.bo.Wydanie
2864 [main] INFO org - class2:class pl.imedia.magazyn.bo.ElementRuchuMagazynowego
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.