Hi,
I have a db with five data and two foreign key into the same table:
- id (int, PK)
- question (varchar)
- result (varchar)
- left_id (int, FK)
- right_id(int, FK)
Here my nodes_bean
Code:
public class Nodes
{
@Id
@GeneratedValue (strategy = GenerationType.IDENTITY)
@Column(name="id")
@NotNull
private int id;
@Column (name = "question")
private String question;
@Column ( name = "result")
private String result;
@OneToOne(fetch= FetchType.LAZY)
@JoinColumn(name="left_id", referencedColumnName="id")
private Nodes left;
@OneToOne(fetch= FetchType.LAZY)
@JoinColumn(name="right_id", referencedColumnName="id")
private Nodes right;
}
without to adding left/right_id integer, my project works.
For example the first line is like this
id:1
question: "are you a man ?"
result: null
left_id: 2
right_id: 3
I can insert a new question and result, but i can't insert left or right_id !
Here my method for to insert new data
Code:
public void insert_question(String question, int left ) throws HibernateException
{
try
{
Session session = getSession();
Transaction tx = session.beginTransaction();
Nodes node = new Nodes();
node.setQuestion(question);
node.setLeftNodes(node.getLeftNodes().getId_node());
session.saveOrUpdate(node);
tx.commit();
session.close();
}
catch (HibernateException e)
{
e.printStackTrace();
}
}
The errors is on
Quote:
node.setLeftNodes(left.getLeftNodes().getId_node());
The message is :
"Cannot invoke getLeftNodes() on the primitive type int".
This is normal beacause i did not left/right_id integer .
My question is : how i can left/right_id when there are a foreign key ?
Thanks