Relationships are the cornerstone of any ORM. Onyx offers flexible assistance for creating object model relationships.
Attribute | Type | Default | Description |
---|---|---|---|
type |
RelationshipType | null | Defines the relationship cardinality. For Example One to One, One to Many, Many to Many, or Many to One |
inverseClass |
Class | null | The type of relationship object(s) |
inverse |
String | The inverse indicates the name of the attribute that corresponds to the annotated relationship. This is identified on the inverse class. | |
fetchPolicy |
FetchPolicy | FetchPolicy.LAZY | Fetch Policy determines when relationship objects are to be hydrated. This only applies to ToMany relationships. |
cascadePolicy |
CascadePolicy | CascadePolicy.NONE | Fetch Policy determines when relationship objects are to be hydrated. This only applies to ToMany relationships. |
loadFactor | Integer | 5 (Value from 1-10) | Load Factor indicates the scalability of the index. If you define 10, it is built to handle large data sets and not degrade over time. Alternatively 1 is for smallest data sets. The lower the load factor, the faster it will be for small amounts of records. This will also reduce the amount of disk space used. |
The following are valid relationship types:
Value | Description |
---|---|
RelationshipType.ONE_TO_ONE |
Constrains each relationship to correspond to a single entity. You must define the attribute type as a class that inherits from ManagedEntity. |
RelationshipType.ONE_TO_MANY |
A single entity can relate to many managed com.onyxdevtools.entities. The defining entity must declare a list of ManagedEntities. The corresponding entity must define the attribute type as a class that inherits from ManagedEntity. The corresponding must also be declared as a RelationshipType.MANY_TO_ONE relationship type. |
RelationshipType.MANY_TO_ONE |
Corresponding relationship to RelationshipType.ONE_TO_MANY. |
RelationshipType.MANY_TO_MANY |
Relationship mapping that indicates a List of entities that are related to a List of corresponding com.onyxdevtools.entities. |
The following are valid fetch policies:
Value | Description |
---|---|
FetchPolicy.EAGER |
Eager fetch policy will load all relationship items upon fetching. Unlike some ORMs, you can specify eager loading on as many relationships as you choose.
Also note that if the relationship entity implements Comparable, the relationships will automatically be sorted. |
FetchPolicy.LAZY |
Lazy Fetch Policy loads relationship placeholders. In order to optimize up front loading cost and save memory, it specifies a list of pointers to relationships that are encapsulated using the LazyRelationshipCollection. When a value is referenced, the pointer will then be hydrated.
You can also use the initialize() method to hydrate a specific relationship. The LazyRelationshipCollection is not sorted upon load. |
FetchPolicy.NONE |
Do not load relationship objects. |
The following are valid cascade policies:
Value | Description |
---|---|
CascadePolicy.SAVE |
Cascade an entity save. If the parent is being persisted or updated, the relationship entities will also be persisted or updated. |
CascadePolicy.DELETE |
Cascade delete upon deleting an entity. If you delete a parent entity, all child relationship entities will be deleted. |
CascadePolicy.ALL |
Adhere to CascadePolicy.SAVE and CascadePolicy.DELETE. |
CascadePolicy.DEFER_SAVE |
When you need more optimization when performing batch persistence, you may want to use DEFER_SAVE. This will prevent cascading when saving. It will also allow batch relationship associations to occur when calling saveRelationshipsForEntity using the Persistence Manager. |
CascadePolicy.NONE |
Do not perform cascading operations on relationship. |
Our goal is to bring about change by enabling people to use simple and quality software in order to make sad engineers happy.
Copyright ©2017 Onyx Development Tools, LLC. All rights reserved.