@JoinColumn(nullable=false)

#1

During the evaluation of ObjectDB (We're currently developing with EclipseLink/mysql) I noticed was the following:

  • I marked a @Column as nullable=false
  • Than I tried to save it with the property as null
  • It worked, without any problem, now I have a corrupt dataset. I expected an exception or something (with EclipseLink/mysql I would get at least an exception from the database)
  • Is there a setting, that I have/need to set; to prevent the object from being saved? Or did I do something wrong?

This is an code example:

//bi-directional many-to-one association to AlarmGroup
@ManyToOne
@JoinColumn(name="alarm_group_id", nullable=false)
private AlarmGroup alarmGroup;
#2

ObjectDB silently ignores RDBMS mapping annotations, including the @JoinColumn annotation (as noted in the API documentation) because data in ObjectDB is not mapped to SQL, tables and columns.

But you can use the optional element of the @ManyToOne and @OneToOne annotations.

Similarly, see this forum thread regarding setting a unique constraint when using ObjectDB.

ObjectDB Support

Reply