@PalmyraForeignKey#

com.palmyralabs.palmyra.base.annotations.PalmyraForeignKey

Declares a foreign-key relationship to another Palmyra type. Target: TYPE. Retention: CLASS — consumed only through @PalmyraMappingConfig.foreignKeys.

You don’t need this annotation for every FK on your model. Palmyra reads foreign keys from JDBC metadata at bootstrap, so a patient column with a DB-level FOREIGN KEY constraint resolves nested-object joins automatically — no annotation required. Reach for @PalmyraForeignKey only when the FK is app-managed: shared/read-only schemas where you can’t add a physical constraint, legacy tables, or views. See @PalmyraMappingConfig — “When you need it” for the decision framing, or Mental Model §2 for the one-screen summary.

Attributes#

Attribute Signature
name String name() — FK name
targetType String targetType() default "" — referenced entity type
targetReference String targetReference() — reference identifier on the target
sourceFields String[] sourceFields() default {}
targetFields String[] targetFields() default {}

Example#

import com.palmyralabs.palmyra.base.annotations.PalmyraForeignKey;
import com.palmyralabs.palmyra.base.annotations.PalmyraMappingConfig;

@PalmyraMappingConfig(
    type = "Order",
    foreignKeys = {
        @PalmyraForeignKey(
            name = "fk_order_user",
            targetType = "User",
            targetReference = "user",
            sourceFields = {"userId"},
            targetFields = {"id"}
        )
    }
)
public class Order { }