Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Basic question about 'optional' attribute

Chris,

Thanks for your pointer to this thread. 

The details are contrary to page 165 of O'Reilly's Enterprise Java Beans 3.1 6th Edition which says, " The optional() attribute is useful for when the persistence provider is generating the database schema for you. When this attribute is set to true, the property is treated as nullable."

Not sure if the O'Reilly book is getting that from the spec or not. Anyhow I'll throw a vote on the referenced bug since it make sense to me that optional is treated that way.

-Noah


On Jul 19, 2012, at 5:27 PM, Christopher Delahunt wrote:

I think you will want to use nullable=false in the column definition.

James wrote a good response to a related question on the difference between nullable vs optional here:
http://www.eclipse.org/forums/index.php/mv/tree/203116/#page_top

Best Regards,
Chris

On 19/07/2012 5:18 PM, Noah White wrote:

I have an Entity with some attributes which look like so:

@Basic(optional = false)
private Long X1;

@Basic(optional = false)
private Long Y1;

My persistence.xml has (among other things):

<property name="eclipselink.target-database" value="Oracle"/>
<property name="eclipselink.ddl-generation" value="create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="sql-script"/>
<property name="eclipselink.application-location" value="C:\ddl"/>


In the create DDL files generated by Eclipselink I am seeing that these columns do not have the NOT NULL constraint on them, rather they look like so:

CREATE TABLE BOX ( ... , X1 NUMBER(19) NULL, Y1 NUMBER(19) NULL, ... )

My understanding of the 'optional' attribute is that it would tell the schema generation process to use NOT NULL so this is surprising to me.

I'm using Eclipselink 2.3.2.v201111250r10461.

-Noah

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top