I have an entity which references another using a join table. However, when I try running I get a
Code:
MappingException: Could not determine type for: com.test.Role, for columns: [org.hibernate.mapping.Column(elt)]
What puzzles me is that it already knows the fully qualified classname for the com.test.Role type; and given the Role class is in the classpath, what else does it need to know?
code exerpts (for the sake of brevity):
Role entity:
Code:
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
@Entity
@Table(name = "role")
public class Role implements GrantedAuthority {
private Integer id;
private String vName;
public Role() {
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID", nullable = false)
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
@Column(name = "V_NAME", nullable = false)
public String getVName() {
return vName;
}
public void setVName(String vName) {
this.vName = vName;
}
}
User entity (which refers to the role):
Code:
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
@Entity @Table(name = "user") public class User{
private Integer id;
private String vName;
private String password;
private java.util.Collection <org.unintelligible.venue.business.om.Role> role;
public User() {
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID", nullable = false)
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(
name="user_role",
joinColumns = { @JoinColumn( name="user_id") },
inverseJoinColumns = @JoinColumn( name="role_id")
)
public java.util.Collection<org.unintelligible.venue.business.om.Role> getRole() {
return role;
}
public void setRole(java.util.Collection<org.unintelligible.venue.business.om.Role> role) {
this.role = role;
}
@Column(name = "V_NAME", nullable = false)
public String getVName() {
return vName;
}
public void setVName(String vName) {
this.vName = vName;
}
@Column(name = "PASSWORD", nullable = false)
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
I am using Hibernate 3.0 CR1 (CR2 doesn't work for me), Annotations 3.1beta9, EntityManager 3.1.0beta8
I must be missing something obvious - I'm not having a problem with any of my other classes which use exactly the same type of mapping. Any help appreciated.
thanks,
Nick