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:
@@ -0,0 +1,50 @@
|
||||
package org.tests.ddl;
|
||||
|
||||
import javax.persistence.ConstraintMode;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.ForeignKey;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
@Entity
|
||||
public class DfkNoneViaJoin {
|
||||
|
||||
@Id
|
||||
long id;
|
||||
|
||||
String name;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "one_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
DfkOne one;
|
||||
|
||||
public DfkNoneViaJoin(String name, DfkOne one) {
|
||||
this.name = name;
|
||||
this.one = one;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public DfkOne getOne() {
|
||||
return one;
|
||||
}
|
||||
|
||||
public void setOne(DfkOne one) {
|
||||
this.one = one;
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,24 @@ public class TestForeignKeyModes extends BaseTestCase {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void noneViaJoin() {
|
||||
|
||||
DfkOne one = new DfkOne("one2");
|
||||
Ebean.save(one);
|
||||
|
||||
DfkNoneViaJoin none = new DfkNoneViaJoin("none2", one);
|
||||
Ebean.save(none);
|
||||
|
||||
// fails unless there is no Foreign key ...
|
||||
Ebean.delete(one);
|
||||
|
||||
DfkNoneViaJoin found = Ebean.find(DfkNoneViaJoin.class, none.getId());
|
||||
assertThat(found).isNotNull();
|
||||
// we still reference one ... even though it does not exist anymore
|
||||
assertThat(found.getOne()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNullOnDelete() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user