25 Mart 2011 Cuma

JPA tips

In this post, i tried to summarize Java Persistence API: Best Practices slides prepared by Carol McDonald and available at http://www.slideshare.net/caroljmcdonald/td09jpabestpractices2.



Two types of persistence context:

  • · Transaction scoped
  • · Extended scoped persistence context




Configure L2 caching for entities that are

  • · read often
  • · modified infrequently
  • · Not critical if stale

protect any data that can be concurrently modified with a locking strategy

  • · Must handle optimistic lock failures on flush/commit
  • · configure expiration, refresh policy to minimize lock failures

Configure Query cache

  • · Useful for queries that are run frequently with the same parameters, for not modified tables

Navigating Entity Relationships

Data fetching strategy

  • · EAGER – immediate

    · LAZY – loaded only when needed

    · LAZY is good for large objects and/or with relationships with deep hierarchies




Database Design Tips

Smaller tables use less disk, less memory, can give better performance

> Use as small data types as possible

> use as small primary key as possible

> Vertical Partition:

split large, infrequently used columns into a separate one-to-one table

Use good indexing

> Indexes Speed up Querys

> Indexes slow down Updates

> Index columns frequently used in Query Where claus


Mapping Inheritance Hierarchies





Transactions

Do not perform expensive and unnecessary operations that are not part of a transaction

> Hurt performance

> Eg. logging – disk write are expensive, resource contention on log

Do not use transaction when browsing data

> @TransactionAttribute(NOT_SUPPORTED)


There is also a blog entry of the same writer about JPA caching, possibly initiated from the slides at http://www.slideshare.net/caroljmcdonald/td09jpabestpractices2 . (http://blogs.sun.com/carolmcdonald/entry/jpa_caching)


Hiç yorum yok:

Yorum Gönder