Hi
I have the following class:
Code:
@Entity
@Table(name = "Category")
public class Category {
@Id
@Column(name = "ID")
private long id;
@Column(name = "Name")
private String name;
@Column(name = "Description")
private String description;
@Column(name = "Parent")
@JoinColumn(name = "ID")
private Category parent;
public Category(){}
public Category(String n, String d, Category c){
this.name = n;
this.description = d;
this.parent = c;
}
public long getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Category getParent() {
return parent;
}
public void setParent(Category parent) {
this.parent = parent;
}
}
My DB is Mysql and the table looks like this:
Code:
mysql> describe category;
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| ID | bigint(20) | NO | PRI | NULL | auto_increment |
| Name | varchar(50) | NO | | NULL | |
| Description | varchar(300) | YES | | NULL | |
| Parent | bigint(20) | YES | | NULL | |
+-------------+--------------+------+-----+---------+----------------+
And also have it in my hibernate.cfg.xml
Code:
<mapping package="papers.entities" />
<mapping class="papers.entities.Category"/>
When I try to insert in Category:
Category cat = new Category("testCat", "test", new Category());
cdao.persistCategory(cat);
I get error:
org.hibernate.MappingException: Could not determine type for: papers.entities.Category, at table: Category, for columns: [org.hibernate.mapping.Column(Parent)]
Anyone has on idea what the problem is? It's been bothering me for hours.
Thank you