mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1748 - Support older JPA API that doesn't have orphanRemoval() or joinColumn.foreignKey()
This commit is contained in:
@@ -69,12 +69,21 @@ class AnnotationAssocManys extends AnnotationParser {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean readOrphanRemoval(OneToMany property) {
|
||||
try {
|
||||
return property.orphanRemoval();
|
||||
} catch (NoSuchMethodError e) {
|
||||
// Support old JPA API
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void read(DeployBeanPropertyAssocMany<?> prop) {
|
||||
|
||||
OneToMany oneToMany = get(prop, OneToMany.class);
|
||||
if (oneToMany != null) {
|
||||
readToOne(oneToMany, prop);
|
||||
if (oneToMany.orphanRemoval()) {
|
||||
if (readOrphanRemoval(oneToMany)) {
|
||||
prop.setModifyListenMode(ModifyListenMode.REMOVALS);
|
||||
prop.getCascadeInfo().setDelete(true);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,6 @@ public class AnnotationAssocOnes extends AnnotationParser {
|
||||
*/
|
||||
@Override
|
||||
public void parse() {
|
||||
|
||||
for (DeployBeanProperty prop : descriptor.propertiesAll()) {
|
||||
if (prop instanceof DeployBeanPropertyAssocOne<?>) {
|
||||
readAssocOne((DeployBeanPropertyAssocOne<?>) prop);
|
||||
@@ -183,9 +182,13 @@ public class AnnotationAssocOnes extends AnnotationParser {
|
||||
}
|
||||
|
||||
private void checkForNoConstraint(DeployBeanPropertyAssocOne<?> prop, JoinColumn joinColumn) {
|
||||
ForeignKey foreignKey = joinColumn.foreignKey();
|
||||
if (foreignKey.value() == ConstraintMode.NO_CONSTRAINT) {
|
||||
prop.setForeignKey(new PropertyForeignKey());
|
||||
try {
|
||||
ForeignKey foreignKey = joinColumn.foreignKey();
|
||||
if (foreignKey.value() == ConstraintMode.NO_CONSTRAINT) {
|
||||
prop.setForeignKey(new PropertyForeignKey());
|
||||
}
|
||||
} catch (NoSuchMethodError e) {
|
||||
// support old JPA API
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,17 +225,24 @@ public class AnnotationAssocOnes extends AnnotationParser {
|
||||
prop.setNullable(propAnn.optional());
|
||||
prop.setFetchType(propAnn.fetch());
|
||||
prop.setMappedBy(propAnn.mappedBy());
|
||||
prop.setOrphanRemoval(readOrphanRemoval(propAnn));
|
||||
if (!"".equals(propAnn.mappedBy())) {
|
||||
prop.setOneToOneExported();
|
||||
prop.setOrphanRemoval(propAnn.orphanRemoval());
|
||||
} else if (propAnn.orphanRemoval()) {
|
||||
prop.setOrphanRemoval(true);
|
||||
}
|
||||
|
||||
setCascadeTypes(propAnn.cascade(), prop.getCascadeInfo());
|
||||
prop.setBeanTable(beanTable(prop));
|
||||
}
|
||||
|
||||
private boolean readOrphanRemoval(OneToOne property) {
|
||||
try {
|
||||
return property.orphanRemoval();
|
||||
} catch (NoSuchMethodError e) {
|
||||
// Support old JPA API
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void readPrimaryKeyJoin(PrimaryKeyJoinColumn primaryKeyJoin, DeployBeanPropertyAssocOne<?> prop) {
|
||||
|
||||
if (!prop.isOneToOne()) {
|
||||
|
||||
Reference in New Issue
Block a user