Hi,
I'm new in this forum and start using Hibernate recently. I will try to detail my problem the best I can.
First: I have two persistent classes: Page and Category.
Second: Into Page class contains one instance of Category class. See example below.
Code:
public class Page {
private int code;
private String name;
private Category category;
// Getters and setters methods
....
}
public class Category {
private int code;
private String name;
}
Third: In my database the tables are mapped. Its are working correctly.
This is my context. My problem is when the Page is stored. The table mapped by the Category class are populated with data.
When I try to insert a Page, a key violation happens in Category Class. How I can store a Page using a Category which already exists in database?. Example
Code:
Category cat = new Category();
cat.setCode(500) // Code 500 already exist in database
Page page = new Page();
page.setName("Test Page");
page.setCategory(cat);
HibernateUtil.store(page) //Violation of key here
How can I do it ??
tanks