Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » optional vs nullable attributes(JPA spec question)
optional vs nullable attributes [message #649109] Mon, 17 January 2011 17:35 Go to next message
Daniel Le Berre is currently offline Daniel Le BerreFriend
Messages: 82
Registered: July 2009
Member
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 14:47 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

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.



James : Wiki : Book : Blog : Twitter
Re: optional vs nullable attributes [message #649773 is a reply to message #649765] Thu, 20 January 2011 14:58 Go to previous messageGo to next message
Daniel Le Berre is currently offline Daniel Le BerreFriend
Messages: 82
Registered: July 2009
Member
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 15:02 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

It would seem logical to use the optional in the DDL if the @Column was not specified. Perhaps log a bug.


James : Wiki : Book : Blog : Twitter
Re: optional vs nullable attributes [message #649785 is a reply to message #649776] Thu, 20 January 2011 15:27 Go to previous message
Daniel Le Berre is currently offline Daniel Le BerreFriend
Messages: 82
Registered: July 2009
Member
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: Thu Dec 18 04:13:51 GMT 2014

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

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