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.