Following the example from Hibernate annotations documentation:
Code:
@Entity
class MedicalHistory implements Serializable {
@Id @OneToOne
@JoinColumn(name = "person_id")
Person patient;
}
@Entity
public class Person implements Serializable {
@Id @GeneratedValue Integer id;
}
I have created my model:
Code:
@Entity
public class Publication extends DefaultFieldPersistent {
@Column(nullable = false)
private Date creationDate = Calendar.getInstance().getTime();
@Column(nullable = false)
private String name;
@Column(nullable = false)
private String author;
@Column(nullable = false)
private String identifier;
// PDF, EPUB, TEXT, HTML
@Column(nullable = false)
private String format;
private Integer licenseCount;
private Integer leaseTime;
public Publication() {
}
}
@Entity
public class PublicationContent implements Persistent<Publication> {
@Id
@OneToOne
private Publication publication;
@Lob
private Blob content;
@SuppressWarnings("unused")
protected PublicationContent() {
}
}
Schema generation works fine. Persisting works fine but trying to session.load(PublicationContext.class, publication):
Quote:
org.springframework.orm.hibernate3.HibernateSystemException: Provided id of the wrong type for class com.mobilebox.biblio.model.PublicationContent. Expected: class com.mobilebox.biblio.model.PublicationContent, got class com.mobilebox.biblio.model.Publication; nested exception is org.hibernate.TypeMismatchException: Provided id of the wrong type for class com.mobilebox.biblio.model.PublicationContent. Expected: class com.mobilebox.biblio.model.PublicationContent, got class com.mobilebox.biblio.model.Publication
which means that Hibernate thinks that the ID class of PublicationContent is PublicationContent which is clearly wrong.
Rewriting the code to match the other example:
Code:
@Entity
class MedicalHistory implements Serializable {
@Id Integer id;
@MapsId @OneToOne
@JoinColumn(name = "patient_id")
Person patient;
}
@Entity
class Person {
@Id @GeneratedValue Integer id;
}
session.load(PublicationContext.class, publication.getId()) works ok in this case.
Am I doing something wrong or is it some kind of a bug?