Skip to content

Concepts

xamry edited this page Nov 8, 2012 · 9 revisions

Rules

  • Entity classes must be annotated with  @Entity
  • Entity classes must be annotated with @Table with name and schema attributes to specify table name and schema name respectively. (Table and schema may have different meaning in different datastores)
  • Schema name should be in the format [Schema Name]@[Persistence Unit Name] if your entity is going to be stored in NoSQL datastores. However, for entities going to be stored in relational database you just specify schema name.
  • Entity classes must have a default no-argument constructor.
  • Each entity must have a field annotated with @Id. This will be persisted as row key.
  • There must be 1 and only 1 @Id per entity.
  • Primary Key and Column fields type must be according to supported data types.
  • All fields annotated with @Embedded and @ElementCollection are stored within the table. e.g. Super column(s) in cassandra and nested document(s) in MongoDB.
  • Fields annotated with @Embedded and @ElementCollection must be a class annotated with @Embeddable with their class definition. (The JPA way!)
  • Relationship entities annotated with @OneToOne, @OneToMany etc must be another entity class. (All above rules apply to them). They are stored as separate tables and foreign keys are maintained by kundera. (we'll get to that later)

Annotations

Kundera does not add any new annotation to the JPA set of annotations. Rather, it gives new meaning to existing ones so that:

  • The time to get started with Kundera is very less and you can journey ahead with Kundera, the usual JPA-way.

  • There is a uniformity in annotation set across all data-stores

  • Some major annotations used by Kundera:

    1. javax.persistence.Entity

    2. javax.persistence.Table

    3. javax.persistence.Id

    4. javax.persistence.Column

    5. javax.persistence.Embedded

    6. javax.persistence.ElementCollection

    7. javax.persistence.CollectionTable

    8. javax.persistence.Embeddable

    9. javax.persistence.OneToOne

    10. javax.persistence.OneToMany

    11. javax.persistence.ManyToOne

    12. javax.persistence.ManyToMany

    13. javax.persistence.JoinColumn

      ...and so on.

  • Here is a graphical representation of what different annotations map to your datastore terminology. Annotation Table


Home

Clone this wiki locally