{"record":{"id":"832a685944c3f3d2","repo":"greenrobot/greenDAO","slug":"currently-only-single-fk-columns-are-supported","errorCode":null,"errorMessage":"Currently only single FK columns are supported: ","messagePattern":"Currently only single FK columns are supported: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"DaoGenerator/src/org/greenrobot/greendao/generator/ToOne.java","lineNumber":93,"sourceCode":"    public boolean isUseFkProperty() {\n        return useFkProperty;\n    }\n\n    void init2ndPass() {\n        if (name == null) {\n            char[] nameCharArray = targetEntity.getClassName().toCharArray();\n            nameCharArray[0] = Character.toLowerCase(nameCharArray[0]);\n            name = new String(nameCharArray);\n        }\n\n    }\n\n    /** Constructs fkColumns. Depends on 2nd pass of target key properties. */\n    void init3ndPass() {\n\n        Property targetPkProperty = targetEntity.getPkProperty();\n        if (fkProperties.length != 1 || targetPkProperty == null) {\n            throw new RuntimeException(\"Currently only single FK columns are supported: \" + this);\n        }\n\n        Property property = fkProperties[0];\n        PropertyType propertyType = property.getPropertyType();\n        if (propertyType == null) {\n            propertyType = targetPkProperty.getPropertyType();\n            property.setPropertyType(propertyType);\n            // Property is not a regular property with primitive getters/setters, so let it catch up\n            property.init2ndPass();\n            property.init3ndPass();\n        } else if (propertyType != targetPkProperty.getPropertyType()) {\n            System.err.println(\"Warning to-one property type does not match target key type: \" + this);\n        }\n        resolvedKeyJavaType[0] = schema.mapToJavaTypeNullable(propertyType);\n        resolvedKeyUseEquals[0] = checkUseEquals(propertyType);\n    }\n\n    protected boolean checkUseEquals(PropertyType propertyType) {","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/greenrobot/greenDAO/blob/0bbb338e17c4cf28aba5aae62d42f73f50186157/DaoGenerator/src/org/greenrobot/greendao/generator/ToOne.java#L75-L111","documentation":"ToOne.init3ndPass() builds the foreign-key column list for a to-one relation. greenDAO's generator only supports a single FK column: if fkProperties has more than one entry, or the target entity has no PK property at all, it throws this RuntimeException naming the relation.","triggerScenarios":"Calling setFkProperties with more than one property on a ToOne; or creating a ToOne to a target entity that has no primary key (getPkProperty() returns null); a ToOne defined against a composite-key target.","commonSituations":"Modeling a to-one relation to an entity with a composite primary key; copying ToMany composite-key patterns onto a ToOne; target entity defined without addIdProperty().primaryKey().","solutions":["Use a single-column primary key on the target entity and a single FK property on the source","Remove extra fkProperties so only one remains, or use entity.addToOne(targetEntity, singleFkProperty)","If you need composite references, use a ToMany or model the join explicitly with an intermediate entity","Ensure the target entity has a PK (addIdProperty().primaryKey()) before the relation's 3rd pass"],"exampleFix":"// before\nToOne toOne = order.addToOne(customer, null);\ntoOne.setFkProperties(custRegionProp, custCodeProp); // 2 FKs\n// after\nToOne toOne = order.addToOne(customer, order.getCustomerIdProperty()); // single FK","handlingStrategy":"validation","validationCode":"if (targetEntity.getPkProperty() == null || fkProps.size() > 1) throw new IllegalStateException(\"ToOne requires single FK and single-PK target\");","typeGuard":"function singleFkValid(fkProps, target) { return Array.isArray(fkProps) && fkProps.length === 1 && target.getPkProperty() != null; }","tryCatchPattern":"try { schema.generate(); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"Currently only single FK columns\")) { simplifyRelation(e.getMessage()); } else { throw e; } }","preventionTips":["Never call setFkProperties with multiple properties on a ToOne","Ensure relation targets use single-column primary keys","Model composite-key references with ToMany or an explicit join entity instead"],"tags":["greendao","codegen","to-one","foreign-key"],"backgroundTag":"unsupported-operation","analyzedSha":"0bbb338e17c4cf28aba5aae62d42f73f50186157","analyzedAt":"2026-09-08T03:22:36.050Z","contentChangedAt":"2026-09-08T03:22:36.050Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}