persistence@glassfish.java.net

RE: Basic.optional() vs. Column.nullable()

From: Gordon Yorke <gordon.yorke_at_oracle.com>
Date: Mon, 26 Feb 2007 10:44:07 -0500

Hello Andrei,
   The difference between optional and nullable is the scope at which they are evaluated. The definition of 'optional' talks about property and field values and suggests that this feature should be evaluated within the runtime. 'nullable' is only in reference to database columns.
   If an implementation chooses to implement optional then those properties should be evaluated in memory by the Persistence Provider and an exception raised before SQL is sent to the database otherwise when using 'updatable=false' 'optional' violations would never be reported.
--Gordon

-----Original Message-----
From: Andrei.Badea_at_Sun.COM [mailto:Andrei.Badea_at_Sun.COM]On Behalf Of
Andrei Badea
Sent: Monday, February 26, 2007 7:48 AM
To: persistence_at_glassfish.dev.java.net
Subject: Basic.optional() vs. Column.nullable()


What is exactly the difference between Basic.optional() and
Column.nullable()? For example, does

@Basic(optional = false)
public int getAge() { ... }

mean the same as

@Column(nullable = false)
public int getAge() { ... }

wrt database column nullability? I know the spec says optional() is a
hint, but what should an implementation do if it decided not to ignore
it? IOW, what was the reason to have both nullable() and optional() in
the spec?

Thanks,

Andrei