Hibernate version:
Hibernate tools 3.1.0.alpha5
Hibernate Annotations 3.1 beta 5
Hibernate 3.1 beta 3
Derby 10.1.1.0
Hi All,
I have a problem with HibernateToolTask 3.1.0 alpha 5 when used Annotations 3.1 beta 5. Adding a mappedBy attribute to a @OneToOne annotation causes an NPE in hbm2ddl. Removing mappedBy fixes the problem but I can not define the owner of the relationship. The code below causes the NPE. There is no stack trace in the Ant console.
Code:
@Entity(access = AccessType.PROPERTY)
public class TaskConstraint implements Serializable{
protected TaskSpec taskSpec;
@OneToOne(mappedBy="taskConstraint")
public TaskSpec getTaskSpec() {
return taskSpec;
}
public void setTaskSpec(TaskSpec taskSpec) {
this.taskSpec = taskSpec;
}
@Entity(access = AccessType.PROPERTY)
public class TaskSpec implements Serializable{
protected TaskConstraint taskConstraint;
@OneToOne
@JoinColumn(name="TASK_CONSTRAINT_FK", nullable=false)
public TaskConstraint getConstraint() {
return taskConstraint;
}
public void setConstraint(TaskConstraint taskConstraint) {
this.taskConstraint = taskConstraint;
}
}
A second problem may be related to the Derby Dialect. At the other end of the relationship, a unique constaint is appllied to the FK in the create table statement. This statement failes as FK is nullable. Adding
Code:
@JoinColumn(name="TASK_CONSTRAINT_FK", nullable=false)
Fixes the problem. However it should not be necessary to define the column name. If a unique contraint is applied, the column should be not null.
Thanks,
Paul