@Retention(value=RUNTIME) @Target(value=FIELD) public @interface DbForeignKey
We can specify if a constraint should not be defined at all or control the onDelete and onUpdate modes used.
@DbForeignKey(onDelete = ConstraintMode.CASCADE)
@ManyToOne
RelatedBean parent;
// No FK Constraint
@DbForeignKey(noConstraint=true)
@ManyToOne
RelatedBean parent;
@DbForeignKey(onDelete = ConstraintMode.SET_NULL)
@ManyToOne
RelatedBean parent;
| Modifier and Type | Optional Element and Description |
|---|---|
boolean |
noConstraint
Set to true when we do not wish any foreign key constraint to be created.
|
boolean |
noIndex
Set to true when we do not wish an index to be created on the foreign key column(s).
|
ConstraintMode |
onDelete
Specify the onDelete mode.
|
ConstraintMode |
onUpdate
Do NOT change this - seriously, don't do it.
|
public abstract ConstraintMode onDelete
public abstract ConstraintMode onUpdate
Your primary keys should never change by design. We should orientate the design to support primary keys that change (and instead find better non mutating primary keys). Oracle go to the point of actively not supporting "on update" for this reason.
So yes, we can specify the onUpdate mode but I don't expect anyone to change this.
public abstract boolean noConstraint
public abstract boolean noIndex
Copyright © 2019. All rights reserved.