mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1228 - Add support to not generate FK Constraint when @JoinColumn(foreignKey=@ForeignKey(ConstraintMode.NO_CONSTRAINT))
This commit is contained in:
@@ -10,6 +10,19 @@ public class PropertyForeignKey {
|
||||
private final ConstraintMode onDelete;
|
||||
private final ConstraintMode onUpdate;
|
||||
|
||||
/**
|
||||
* Construct for "No Constraint".
|
||||
*/
|
||||
public PropertyForeignKey() {
|
||||
this.noConstraint = true;
|
||||
this.noIndex = false;
|
||||
this.onDelete = ConstraintMode.GLOBAL_DEFAULT;
|
||||
this.onUpdate = ConstraintMode.GLOBAL_DEFAULT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct for the mapping annotation.
|
||||
*/
|
||||
public PropertyForeignKey(DbForeignKey dbForeignKey) {
|
||||
this.noIndex = dbForeignKey.noIndex();
|
||||
this.noConstraint = dbForeignKey.noConstraint();
|
||||
|
||||
@@ -16,8 +16,10 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.ConstraintMode;
|
||||
import javax.persistence.Embedded;
|
||||
import javax.persistence.EmbeddedId;
|
||||
import javax.persistence.ForeignKey;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
@@ -131,6 +133,7 @@ public class AnnotationAssocOnes extends AnnotationParser {
|
||||
if (!joinColumn.nullable()) {
|
||||
prop.setNullable(false);
|
||||
}
|
||||
checkForNoConstraint(prop, joinColumn);
|
||||
}
|
||||
|
||||
|
||||
@@ -171,6 +174,13 @@ public class AnnotationAssocOnes extends AnnotationParser {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkForNoConstraint(DeployBeanPropertyAssocOne<?> prop, JoinColumn joinColumn) {
|
||||
ForeignKey foreignKey = joinColumn.foreignKey();
|
||||
if (foreignKey != null && foreignKey.value() == ConstraintMode.NO_CONSTRAINT) {
|
||||
prop.setForeignKey(new PropertyForeignKey());
|
||||
}
|
||||
}
|
||||
|
||||
private String errorMsgMissingBeanTable(Class<?> type, String from) {
|
||||
return "Error with association to [" + type + "] from [" + from + "]. Is " + type + " registered?";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user