I have followed the examples, but have never been able to get a Bidirectional OneToOne association to work.
Code:
@Entity
public class Server implements Serializable {
private int serverId;
private Task task;
@Id
@Column(name="server_id")
public int getServerId() {
return serverId;
}
@OneToOne
@PrimaryKeyJoinColumn
// @JoinColumn(name="task_id")
public Task getTask() {
return task;
}
}
@Entity
public class Task implements Serializable {
private int taskId;
private Server server;
@Id
@Column(name="task_id")
public int getTaskId() {
return taskId;
}
@OneToOne(mappedBy = "server_id")
public Server getServer() {
return server;
}
}
hibernatetool always gets a NullPointerException with the above code. If I comment out the getServer method and annotation, then I have a unidirectional association, but I still get the following error from hibernate tool:
hibernatetool org.hibernate.tool.hbm2x.ExporterException: Error while processing template hbm/hibernate-mapping.hbm.ftl
hibernatetool freemarker.template.TemplateException: Error reading included file hbm/one-to-one.hbm.ftl
hibernatetool java.io.FileNotFoundException: Template hbm/one-to-one.hbm.ftl not found.
Furthermore, if I change PrimaryKeyJoinColumn to JoinColumn, then the unidirectional association finally works.
I'm using
Hibernate 3.2.2.ga
HibernateAnnotations 3.3.0.GA
HibernateTools 3.2.0.beta8
Freemarker 2.3.4
How do I get the bidirectional association to work correctly? What is the deal with the *.hbm.ftl files?