protected void createInitializers(final JavaClassSource entity) throws FacetNotFoundException, FileNotFoundException { boolean dirtyBit = false; for (FieldSource<JavaClassSource> field : entity.getFields()) { if (field.hasAnnotation(OneToOne.class)) { AnnotationSource<JavaClassSource> oneToOne = field.getAnnotation(OneToOne.class); if (oneToOne.getStringValue("mappedBy") == null && oneToOne.getStringValue("cascade") == null) { oneToOne.setEnumValue("cascade", CascadeType.ALL); dirtyBit = true; } String methodName = "new" + StringUtils.capitalize(field.getName()); if (!entity.hasMethodSignature(methodName)) { entity .addMethod() .setName(methodName) .setReturnTypeVoid() .setPublic() .setBody("this." + field.getName() + " = new " + field.getType().getName() + "();"); dirtyBit = true; } } } for (MethodSource<JavaClassSource> method : entity.getMethods()) { if (method.hasAnnotation(OneToOne.class)) { AnnotationSource<JavaClassSource> oneToOne = method.getAnnotation(OneToOne.class); if (oneToOne.getStringValue("mappedBy") == null && oneToOne.getStringValue("cascade") == null) { oneToOne.setEnumValue("cascade", CascadeType.ALL); dirtyBit = true; } String fieldName = StringUtils.camelCase(method.getName().substring(3)); String methodName = "new" + StringUtils.capitalize(fieldName); if (!entity.hasMethodSignature(methodName)) { entity .addMethod() .setName(methodName) .setReturnTypeVoid() .setPublic() .setBody("this." + fieldName + " = new " + method.getReturnType().getName() + "();"); dirtyBit = true; } } } if (dirtyBit) { this.project.getFacet(JavaSourceFacet.class).saveJavaSource(entity); } }