I would like to define a @ManyToOne relationship with optional parameter.(eg wordtype below)
I use spring 2.0.3 with Hibernate 3.2.2 GA with JPA, PostgreSQL 8.1.
When the database created automatically the table contains not null constraints however I have defined the field as optional(can be null).
It is the same case if I use @OneToOne.
Is it a bug or I have made any mistake?
My entity definition:
public class DictionaryWord extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "id", columnDefinition = "NUMERIC(18) NOT NULL")
private Long id;
@Column(nullable=false)
private String dictionaryWord;
@ManyToOne(optional = true)
@JoinColumn(nullable=true)
private WordType wordtype=null;
}
@Entity
public class WordType extends BaseEntity {
@Id
@Column(name = "code", columnDefinition = "VARCHAR(20) NOT NULL")
private String code;
@Column(nullable=false)
private String wordTypeName;
}
|