@Column(nullable) versus @Basic(optional)

View: New views
3 Messages — Rating Filter:   Alert me  

@Column(nullable) versus @Basic(optional)

by cowwoc :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

What is the difference between @Column(nullable) and @Basic(optional)? Don't they amount to the same thing?

Thank you,
Gili

Re: @Column(nullable) versus @Basic(optional)

by James Sutherland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I suppose they technically do.  However "nullable" is used only as a column property for table creation, and is not used at runtime in mapping.  It can be on any column used in any mapping, not just a Basic.

"optional" is a property of the mapping, it is not used during table creation, and is used at runtime to validate an object instance (by some providers).

So the end result is the same, an error will occur for null, but for Column the database will throw the error, and for Basic the JPA provider (may) throw the error.

Re: @Column(nullable) versus @Basic(optional)

by cowwoc :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks James! I appreciate you taking the time to answer me :)

Gili
LightInTheBox - Buy quality products at wholesale price!