My answer: all of the following should be redefined (i.e. describe them all in columndefinition , if necessary):
lengthprecisionscalenullableunique
i.e. a DDL column will consist of: name + columndefinition and nothing else.
The rationale follows.
Annotations containing the word "Column" or "Table" are purely physical properties that are used only for managing DDL / DML with the database.
Other notes are purely logical - properties used in memory in java to control JPA processing.
That's why it sometimes seems that the / nullability option is set twice - once through @Basic(...,optional=true) and once through @Column(...,nullable=true) . The former says that the attribute / association may be null in the JPA object model (in memory) during cleanup; the latter says the DB column may be null. Usually you want them to install the same, but not always, depending on how the database tables are installed and reused.
In your example, the length and nullable properties are overridden and redundant.
So, when specifying columnDefinition do other @Column properties become redundant?
In JPA Spec and javadoc:
columndefinition definition: An SQL fragment that is used when generating DDL for a column.
columndefinition default: Generated SQL to create a column of the output type.
The following examples are provided:
@Column(name="DESC", columnDefinition="CLOB NOT NULL", table="EMP_DETAIL") @Column(name="EMP_PIC", columnDefinition="BLOB NOT NULL")
And, Iβm wrong ... this is really so .: - $ ?!
Does columnDefinition indicate other properties provided in a single annotation?
The javadoc and JPA specification does not explain this explicitly - the specification does not provide much protection. To be 100% sure, test your chosen implementation.
From the examples given in the JPA specification
we can safely mean the following:name and table can be used with columndefinition and they are not overriddennullable overridden / reserved with columndefinition
From the "logic of the situation" we can rightly do the following: (I just said that ??: -P):
length , precision , scale overridden / made redundant with columndefinition - they are an integral part of typeinsertable and updateable provided separately and are never included in columndefinition , since they control the generation of SQL in memory before it is sent to the database.
This leaves the property " unique ". It is similar to nullable - it extends / qualifies a type definition, therefore it should be considered as an integral type definition. that is, it must be redefined.
Check my answer For columns "A" and "B", respectively:
@Column(name="...", table="...", insertable=true, updateable=false, columndefinition="NUMBER(5,2) NOT NULL UNIQUE" @Column(name="...", table="...", insertable=false, updateable=true, columndefinition="NVARCHAR2(100) NULL"
- confirmation of the generated table has the correct type / validity / uniqueness
- optionally insert and update JPA: the former should include column A, the last column B
Glen Best Jul 05 '13 at 6:09 2013-07-05 06:09
source share