Hibernate version: 3
I'm trying to switch domain from xml mapping to annotations but I have a problem. Hibernate throws error:
Invocation of init method failed; nested exception is org.hibernate.MappingException: Could not determine type for: domain.Category, for columns: [org.hibernate.mapping.Column(parentId)]
old xml file ( working fine):
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="domain.Category" table="categories" lazy="false">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="name">
<column name="name"/>
</property>
<many-to-one
name="category"
cascade="all"
column="parentId"
foreign-key="FK_CATEGORIES_1" />
<property name="active">
<column name="active"/>
</property>
</class>
</hibernate-mapping>
Domain was normal setter and getter.
New annoted domain class:
Code:
/**
*
*/
package domain;
import javax.persistence.*;
/**
* @author Michał Warecki
*
*/
@Entity
@AttributeOverride( name="category", column = @Column(name="parentId") )
public class Category{
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
private String name;
private Category category;
private Integer active;
public Category() {
}
public Integer getId(){
return id;
}
public void setId(Integer id){
this.id = id;
}
@Column (name="name")
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@JoinTable( name="Category",
joinColumns = @JoinColumn(name="id"),
inverseJoinColumns = @JoinColumn(name="parentId")
)
public Category getCategory(){
return category;
}
public void setCategory(Category category){
this.category = category;
}
@Column (name="active")
public Integer getActive(){
return active;
}
public void setActive(Integer active){
this.active = active;
}
}
I'm new with hibernate. Can somebody help me with this error? I can't solved it :-/
Thx for help !