I recently started my first Java project that uses Hibernate (and JPA Annotations) for persistence.
I've got the following classes:
User class
*some imports*
@Entity
public class Owner {
private int id;
private String name;
@OneToOne(fetch=FetchType.LAZY)
@JoinColumn(name="id")
private Pet pet;
@Id
@GeneratedValue
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setPet(Pet pet) {
this.pet = pet;
}
public Pet getPet() {
return pet;
}
}
Pet Class
*some imports*
@Entity
public class Pet {
private String name;
@Id
@GeneratedValue
private int id;
public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Whenever I try to save an object, Hibernate gives me the following error output.
Exception in thread "main" org.hibernate.MappingException: Could not determine type for: Pet, at table: Owner, for columns: [org.hibernate.mapping.Column(pet)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:306)
at org.hibernate.mapping.Column.getSqlTypeCode(Column.java:164)
What am I missing? I can't figure out how to do this PF-FK mapping.
Do I need to tell Hibernate which table Pet maps into or is it smart enough to do that? Could someone please suggest how I can change my declaration of the Pet ivar so that Hibernate and I can be happy? :)
Thanks!