Hello,
I've got a strange problem with hibernate and a bidirectional reflexive association in order to realize a tree. Here's the class with the appropriate annotations.
Code:
public class Node extends HibernateObject
{
private String name="";
@OneToMany
@IndexColumn(name="subNodesIndex", base=0)
@JoinTable(name="Node_Node",
joinColumns={@JoinColumn(name="parentNode_ID")},
inverseJoinColumns={@JoinColumn(name="subNode_ID")})
private List<Node> subNodes = new Vector<Node>();
@ManyToOne
@JoinTable(name="Node_Node",
joinColumns={@JoinColumn(name="subNode_ID")},
inverseJoinColumns={@JoinColumn(name="parentNode_ID")})
private Node parentNode = null;
}
I'm using a join table so that Hibernate knows that it's one association. When loading the list of all nodes, the hql statement "FROM Node" gets executed. But Hibernate transforms the query in this way
Code:
SELECT name, parentNode_ID FROM Node
which is apparently incorrect because parentNode_ID is not an attribute of the nodes table. Thus, I get an error message like this one
Code:
Unknown column 'node0_.parentNode_ID' in 'field list'
and the execution of the query fails. What am I doing wrong? The hibernate version in use is 3.2.5.ga. Any help would be greatly appreciated. Thanks in advance,
blabla