Hibernate Overview

JPA Life Cycle


Interceptors (HIbernate) or JPA Callback methods


  • @PrePersist – before a new entity is persisted (added to the EntityManager).
  • @PostPersist – after storing a new entity in the database (during commit or flush).
  • @PostLoad – after an entity has been retrieved from the database.
  • @PreUpdate – when an entity is identified as modified by the EntityManager.
  • @PostUpdate – after updating an entity in the database (during commit or flush).
  • @PreRemove – when an entity is marked for removal in the EntityManager.
  • @PostRemove – after deleting an entity from the database (during commit or flush).

Secondary Cache

Common Annotations

  • @Entity — mapping class to table
  • @Table — specify actual table for class
  • @SecondaryTable – mapping one class to two tables
  • @Column – mapping column to table
  • @Emmedable – the thingy inside a class – for two classes to one table
  • @Embedded – the thing that has the class – for two classes for one table
  • Compound Keys
    1. Use Embeddale/Embedded
    2. @IdClass -declare Compound Key at top of class
    3. @EmbeddedId – declared Id in the middle of class
  • @GeneratedValue(strategy =
    1. AUTO – choose best strategy
    2. IDENTITY – database chooses key
    3. SEQUENCE – uses SQL sequence
    4. TABLE — use @TableGenerator to define table and use values from that
  • ColumnMapping
    • use @JoinColumn
      • what is the name of the column to map back (only in table – not in POJO)
    • for BI-directional use mappedBy in mapping to say what the ID imaps back
  • @ManyToOne –
  • @OneToOne
  • @OneToMany
  • @ManytoMany e.g. Many to One -> @JoinTable <- One to Many

Performance Consideration

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s