You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by tovarisch <is...@gmail.com> on 2011/04/27 19:11:55 UTC
TYPE() function problem
Hi all,
I'm starting with JPA and I found a strange behaviour using TYPE() function
and inherited classes.
Let's have two hierarchical classes:
@Entity
@Table(name="nodes")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="type",
discriminatorType=DiscriminatorType.STRING)
public abstract class Node implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.TABLE, generator="node")
@TableGenerator(name="node", table="idgenerator", pkColumnName="generator",
valueColumnName="lastId", pkColumnValue="node" )
@Column(name="id")
private long id;
@ManyToOne
@JoinColumn(name="parentId")
private Node parent;
@OneToMany(mappedBy="parent", cascade=CascadeType.ALL)
@OrderColumn(name="childIndex")
private List<Node> children;
/* getters & setters & logic methods*/
}
@Entity
@DiscriminatorValue(value="F")
public class Folder extends Node implements Serializable {
/* ...*/
}
The query
SELECT n FROM Node n WHERE TYPE(n)=Folder
generates the following SQL:
SELECT t0.id, t0.type, t1.id, t1.type
FROM nodes t0 LEFT OUTER JOIN nodes t1 ON t0.parentId = t1.id WHERE
(t0.type = 'F')
but this query:
SELECT n FROM Node n WHERE TYPE(n.parent)=Folder
generates exactly the same SQL, returning the nodes that are folders,
instead of the nodes which parent is a folder.
Reading the spec I understand that this last query is valid. Am I doing
something wrong?
Thanks.
--
View this message in context: http://openjpa.208410.n2.nabble.com/TYPE-function-problem-tp6310346p6310346.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: SQL generated by TYPE() function
Posted by Michael Dick <mi...@gmail.com>.
Looks correct to me. There's a similar example in
https://fisheye6.atlassian.com/browse/openjpa/tags/2.1.0/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/polymorphic/TestTablePerClassInheritanceWithAbstractRoot.java?r=1071316
this testcase (line 203).
-mike
--
View this message in context: http://openjpa.208410.n2.nabble.com/SQL-generated-by-TYPE-function-tp6310346p6334495.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: SQL generated by TYPE() function
Posted by tovarisch <is...@gmail.com>.
Hi all,
Could anyone confirm that the query is correct?
SELECT n FROM Node n WHERE TYPE(n.parent)=Folder
Thank you very much.
--
View this message in context: http://openjpa.208410.n2.nabble.com/SQL-generated-by-TYPE-function-tp6310346p6333672.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.