Hibernate version:
Hibernate 3.2
Hibernate Annotations 3.2.0.CR2
Name and version of the database you are using:
McKoi Database v.1.0.3
The Problem
I'm trying to save two entities in the database.
They have a One-to-One relationship sharing primary keys, but their values stored in the database differ.
When i saw that i tried to use an incremental @GenericGenerator in one of the classes and a foreign @GenericGenerator in the other,
but i don't know how to make it work.
The Code
This is a short example of code, assuming that class/variables names and database table/field names are the same.
I saw an example (I'm not really sure if it was) in a taiwanese forum and tried to apply it to my code.
Here's the URL:
http://www.javaworld.com.tw/jute/post/view?bid=54&id=205471
Here's the code:
NOTE: In my code both PK's have the same name.
//FIRST CLASS
@Entity
@Table(name = "Body")
public class Body implements java.io.Serializable{
private int body_PK;
private Heart heart;
public Body() {
}
@Id
@GeneratedValue(generator = "BodyPKGenerator")
@GenericGenerator(name="BodyPKGenerator",
strategy = "increment")
public int getBody_PK() {
return body_PK;
}
public void setBody_PK(int body_PK) {
this.body_PK = body_PK;
}
@OneToOne(cascade = CascadeType.ALL)
@PrimaryKeyJoinColumn
public Heart getHeart() {
return heart;
}
public void setHeart(Heart heart) {
this.heart = heart;
}
}
//SECOND CLASS
@Entity
@Table(name = "Heart")
public class Heart implements java.io.Serializable{
private int Heart_PK;
private boolean healthy;
public Heart(){
}
@Id @GeneratedValue(generator="foreign")
@GenericGenerator(
name = "foreign",
strategy = "foreign",
parameters = @Parameter(name = "property", value = "body")
)
public int getHeart_PK() {
return Heart_PK;
}
@OneToOne(cascade = CascadeType.ALL, mappedBy = "heart")
private Body body;
public void setHeart_PK(int Heart_PK) {
this.Heart_PK = Heart_PK;
}
public boolean isHealthy() {
return healthy;
}
public void setHealthy(boolean healthy) {
this.healthy = healthy;
}
}
The Error
org.hibernate.HibernateException: Unable to resolve property: heart
I'm pretty sure that i've missed something and any help will be appreciated.
Thanks in advance and sorry for my bad english.