Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » optional vs nullable attributes(JPA spec question)
optional vs nullable attributes [message #649109] Mon, 17 January 2011 12:35 Go to next message
Eclipse UserFriend
Dear all,

I have a question regarding the meaning of the optional attribute that can be found on @Basic or relationship annotations and the nullable attribute that can be found in @Column and @JoinColumn annotations.

Isn't @Basic(optional=false) a hint for the JPA provider to make the underlying column not nullable?

I had the idea that the optional attribute on the object side was equivalent to the nullable attribute on the relational side.

Cheers,

Daniel
Re: optional vs nullable attributes [message #649765 is a reply to message #649109] Thu, 20 January 2011 09:47 Go to previous messageGo to next message
Eclipse UserFriend
The nullable attribute controls DDL generation (only).

The optional may be used for validation in the object model. Is has no affect of DDL generation Currently I do not think EclipseLink uses the optional for any validation.

Re: optional vs nullable attributes [message #649773 is a reply to message #649765] Thu, 20 January 2011 09:58 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for the answer James.

Wouldn't it make sense to take into account the optional flag into account in the DDL generation?

If I know in the object model that an attribute is mandatory, I should have a non nullable column in the table, right?

I try to use JPA annotations in such a way to define all my constraints on the object model, and to avoid database specific annotations by all means.

Changing the optional attribute value without seeing any effect on the DDL generation looks odd to me.
Re: optional vs nullable attributes [message #649776 is a reply to message #649773] Thu, 20 January 2011 10:02 Go to previous messageGo to next message
Eclipse UserFriend
It would seem logical to use the optional in the DDL if the @Column was not specified. Perhaps log a bug.
Re: optional vs nullable attributes [message #649785 is a reply to message #649776] Thu, 20 January 2011 10:27 Go to previous message
Eclipse UserFriend
Done.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=334899
Previous Topic:Persisting PGgeomerty with custom SRID
Next Topic:[Fixed] NPE when using LAZY loading on ManyToOne relationship
Goto Forum:
  


Current Time: Sat Jul 05 17:12:57 EDT 2025

Powered by FUDForum. Page generated in 0.43375 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top