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