-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: bidirectional reflexive OneToMany association
PostPosted: Mon Sep 08, 2008 8:02 am 
Newbie

Joined: Fri Mar 14, 2008 9:53 am
Posts: 2
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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 09, 2008 8:12 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Well, it's just that - the node does not exist.

Could you perhaps run a SchemaExport on the class and have Hibernate create the tables? Then the table and column it needs would be created and would exist. Possible?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.