Relationship (cayenne-doc: Cayenne Documentation 5.0-M2 API)
Description: declaration: package: org.apache.cayenne.map, class: Relationship

# Class Relationship<E extends Entity<E,A,R>, A extends Attribute<E,A,R>, R extends Relationship<E,A,R>>

java.lang.Object
org.apache.cayenne.map.Relationship<E,A,R>

All Implemented Interfaces:
  `Serializable, CayenneMapEntry, XMLSerializable`

Direct Known Subclasses:
  `DbRelationship, ObjRelationship`

public abstract class Relationship<E extends Entity<E,A,R>, A extends Attribute<E,A,R>, R extends Relationship<E,A,R>> extends Object implements CayenneMapEntry, XMLSerializable, Serializable
Defines a relationship between two entities. In a DataMap graph relationships represent "arcs" connecting entity "nodes". Relationships are directional, i.e. they have a notion of source and target entity. This makes DataMap a "digraph".

See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected String`
  `name`
  `protected boolean`
  `runtime`
  A flag that specifies whether a Relationship was mapped by the user or added dynamically by Cayenne runtime.
  `protected E`
  `sourceEntity`
  `protected String`
  `targetEntityName`
  `protected boolean`
  `toMany`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Relationship()`
  Creates an unnamed relationship.
  `Relationship(String name)`
  Creates a named relationship.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `String`
  `getName()`
  Returns the name property of this object.
  `Object`
  `getParent()`
  Returns the parent map.
  `abstract Relationship<E,A,R>`
  `getReverseRelationship()`
  Returns a "complimentary" relationship going in the opposite direction.
  `E`
  `getSourceEntity()`
  Returns relationship source entity.
  `abstract E`
  `getTargetEntity()`
  Returns a target entity of the relationship.
  `String`
  `getTargetEntityName()`
  Returns the name of a target entity.
  `abstract boolean`
  `isMandatory()`
  Returns if relationship is mandatory
  `boolean`
  `isRuntime()`
  `boolean`
  `isToMany()`
  Returns a boolean value that determines relationship multiplicity.
  `void`
  `setName(String name)`
  `void`
  `setParent(Object parent)`
  Stores the parent map.
  `void`
  `setRuntime(boolean synthetic)`
  `void`
  `setSourceEntity(E sourceEntity)`
  Sets relationship source entity.
  `void`
  `setTargetEntityName(String targetEntityName)`
  Sets the name of relationship target entity.
  `void`
  `setTargetEntityName(Entity<E,A,R> targetEntity)`
  Sets relationship target entity.
  `String`
  `toString()`
  Overrides Object.toString() to return informative description.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface XMLSerializable

  `encodeAsXML`
  Modifier and Type
  Method
  Description
  `void`
  `encodeAsXML(XMLEncoder encoder, ConfigurationNodeVisitor<?> delegate)`
  Prints itself as XML to the provided XMLEncoder.

- ## Field Details

  - ### name

    protected String name

  - ### sourceEntity

    protected E extends Entity<E,A,R> sourceEntity

  - ### targetEntityName

    protected String targetEntityName

  - ### toMany

    protected boolean toMany

  - ### runtime

    protected boolean runtime
    A flag that specifies whether a Relationship was mapped by the user or added dynamically by Cayenne runtime.
    Since:
      3.0

- ## Constructor Details

  - ### Relationship

    public Relationship()
    Creates an unnamed relationship.

  - ### Relationship

    public Relationship(String name)
    Creates a named relationship.

- ## Method Details

  - ### getName

    public String getName()
    Description copied from interface: `CayenneMapEntry`
    Returns the name property of this object.
    Specified by:
      `getName` in interface `CayenneMapEntry`
    Returns:
      name of this entry.

  - ### setName

    public void setName(String name)

  - ### getSourceEntity

    public E getSourceEntity()
    Returns relationship source entity.

  - ### setSourceEntity

    public void setSourceEntity(E sourceEntity)
    Sets relationship source entity.

  - ### getTargetEntity

    public abstract E getTargetEntity()
    Returns a target entity of the relationship.

  - ### setTargetEntityName

    public void setTargetEntityName(Entity<E,A,R> targetEntity)
    Sets relationship target entity. Internally calls `setTargetEntityName`.

  - ### getTargetEntityName

    public String getTargetEntityName()
    Returns the name of a target entity.

  - ### setTargetEntityName

    public void setTargetEntityName(String targetEntityName)
    Sets the name of relationship target entity.

  - ### isToMany

    public boolean isToMany()
    Returns a boolean value that determines relationship multiplicity. This defines semantics of the connection between two nodes described by the source and target entities. E.g. to-many relationship between two Persistent object classes means that a source object would have a collection of target objects. This is a read-only property.

  - ### getParent

    public Object getParent()
    Description copied from interface: `CayenneMapEntry`
    Returns the parent map.
    Specified by:
      `getParent` in interface `CayenneMapEntry`

  - ### setParent

    public void setParent(Object parent)
    Description copied from interface: `CayenneMapEntry`
    Stores the parent map.
    Specified by:
      `setParent` in interface `CayenneMapEntry`

  - ### toString

    public String toString()
    Overrides Object.toString() to return informative description.
    Overrides:
      `toString` in class `Object`

  - ### isRuntime

    public boolean isRuntime()
    Since:
      3.0

  - ### setRuntime

    public void setRuntime(boolean synthetic)
    Since:
      3.0

  - ### getReverseRelationship

    public abstract Relationship<E,A,R> getReverseRelationship()
    Returns a "complimentary" relationship going in the opposite direction. Returns null if no such relationship is found.
    Since:
      3.1

  - ### isMandatory

    public abstract boolean isMandatory()
    Returns if relationship is mandatory
    Since:
      3.1