-->
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: Mapping one to one on the same table
PostPosted: Tue Apr 22, 2014 7:34 am 
Newbie

Joined: Tue Apr 22, 2014 7:21 am
Posts: 2
Hi,

I have one table (node) with 3 data:
- id (PK)
- question
- result

and two foreign key on the same table
- left_id
- right_id

But when i deploy my project, i have this error

"Exception Description: Circular mappedBy references have been specified (Class: [class com.beans.Nodes], attribute: [left_id] and Class: [class com.beans.Nodes], attribute: [left_id]. This is not valid, only one side can be the owner of the relationship. Therefore, specify a mappedBy value only on the non-owning side of the relationship."


Here my bean

Code:
@Entity
@Table (name = "node")
public class Nodes
{
   @Id
   @GeneratedValue (strategy = GenerationType.IDENTITY)
   @Column(name="id")
   private int id;
   
   @Column (name = "question")
   private String question;
   
   @Column ( name = "result")
   private String result;
   
   @OneToOne(mappedBy="left_id")
   private Nodes left_id;
   
   @OneToOne(mappedBy="right_id")
   private Nodes right_id;   
   
   public Nodes(int id, String question, String result, Nodes left, Nodes right)
   {
          this.id=id;
          this.question=question;
          this.result=result;
          this.left_id=left;
          this.left_id=right;
   }
   
   public Nodes()
   {
      
   }
   
   public Nodes(String question)
   {
      this.question=question;
   }
   
   public Nodes(int id, String result)
   {
      this.id = id;
      this.result = result;
   }

   public void setId_node(int id_node)
   {
      this.id = id_node;
   }


   public int getId_node()
   {
      return id;
   }

   public void setQuestion (String question)
   {
      this.question = question;
   }
   
   public String getQuestion()
   {
      return this.question;
   }
   
   public void setResult (String unResult)
   {
      result = unResult;
   }
   
   public String getResult()
   {
      return this.result;
   }
   
   public Nodes getLeftNodes()
   {
      return left_id;
   }
   
   public void setLeftNodes(Nodes left)
   {
      this.left_id=left;
   }
   
   public Nodes getRightNodes()
   {
      return left_id;
   }
   
   public void setRifhtNodes(Nodes right)
   {
      this.right_id=right;
   }


and my hbm
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="com.beans.Nodes" table="node">
        <id name="id" type="int" access="field">
            <column name="id" />
            <generator class="assigned" />
        </id>
        <property name="question" type="java.lang.String">
            <column name="question" />
        </property>
        <property name="result" type="java.lang.String">
            <column name="result" />
        </property>
         
         <one-to-one name="left_id" class="com.beans.Nodes" access="field"></one-to-one>
        <one-to-one name="right_id" class="com.beans.Nodes" access="field"></one-to-one>
    </class>
</hibernate-mapping>


Where is my problem ?

thanks


Top
 Profile  
 
 Post subject: Re: Mapping one to one on the same table
PostPosted: Thu Apr 24, 2014 2:50 pm 
Newbie

Joined: Mon Apr 14, 2014 11:03 am
Posts: 8
Location: Orlando, FL
Have you tried removing the mappedBy argument?


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.