12 4月 2010

JPA2(1)--Basic Annotation

  • @Entity
    當Class被標識為@Entity,代表這個Class可以被persist至DB,而該Class中的Field除特別以@Transient標記外皆預定會被儲存。
  • @Id
    每個Entity都需要ID做為識別的基準,產生ID的方式由@GeneratedValue來決定
    @GeneratedValue
    strategy => GenerationType:AUTO, TABLE, SEQUENCE, IDENTITY
    GenerationType.AUTO 雖然方便,但建議僅供開發或Prototyping使用
    GenerationType.TABLE 再利用@TableGenerator來指定記錄key的Table相關資料
    GenerationType.SEQUENCE 部份DB支援Sequence, 利用DB的Sequence功能,也可以使用@SequenceGenerator來指定Sequence相關資料.
    GenerationType.IDENTITY 部份DB支援identity column,這方式有個缺點,就是ID一定要在Insert之後才能確認。
  • @Access
    指出JPA存取Field的方式
    AccessType.FIELD: 利用refection存取Field,無視getter跟setter,但是field的visibility不得定為public。例如:@Id private int id;
    AccessType.PROPERTY: 利用getter跟setter來存取field,但getter/setter的visibility一定要定為public或protected。例如:@public int getId() { return id; }
  • @Transient
    表示該field不會被persist
  • @Table
    提供Table name及所屬schema或catalog name
  • @Column
    指定所存的Column Name
  • @Enumerated
    記錄enum所用,ORDINAL用數字而STRING則以文字記錄該property.
    EnumType.ORDINAL, EnumType.STRING
  • @Temporal
    記錄時間用如java.util.Date、java.util.Calendar所用,如果是javax.sql.Date之類的就不用多費心了。
    DATE, TIME, TIMESTAMP
  • @Basic
    可以指定Fetch的方式,利用FetchType.LAZY可減少不必要的Query
    FetchType.LAZY FetchType.EAGER
  • @Lob
    CLOB char[] or BLOB byte[]

11 則留言:

匿名 提到...

Hi there to every one, because I am truly keen of reading this web site's post to be updated daily.
It consists of pleasant data.

Also visit my site; the simpsons tapped out hack

匿名 提到...

I every time emailed this web site post page to all my friends, because if like to read it after that my friends will too.


Also visit my blog post - top eleven hack (http://www.dressapple.net)

匿名 提到...

My brother suggested I might like this blog. He was entirely right.
This post actually made my day. You cann't imagine just how much time I had spent for this information! Thanks!



Have a look at my homepage; cenaless onde comprar

匿名 提到...

You set your mind to investigate every single room. This
can be a huge factor in attending this week long celebration. com and Expedia rooms
up front at the wholesale rate and they are to pay back the wholesale amount to them when they sell a room.



Review my site - kaskade ultra music festival 2014

匿名 提到...

ӏ every time used to read artіcle in news papers but now ɑs I am a user ߋf net therefore from now
I аm using net for posts, thanks to web.

my web blog :: télécharger driver booster

匿名 提到...

I couldn't refrain from commenting. Very well written!

my page ... goji berry onde comprar

匿名 提到...

Love splendor is on the way to be the dynamics of human being being, so that you simply will make them pretty-looking, several of them
go on the diet, some hold exercise, some consume medicine and other people even turn to operation for help.
There is no doubt how the hcg phase 3 food list is finding extra and
extra wanted and several individuals have wondered whether or
not it certainly performs or not. Phase three
- This phase starts after you have finally accomplished the weight which you would
like to reach and can stop taking the drops. Taking all things into consideration, you may need to take Metforming for
about three to six months before other treatment options can be
added to it. Make sure that you remove all articles of clothing.
' Only other drinks allowed are herbal teas, green tea,
and the occasional black coffee. Many patients see a dramatic weight loss, but the weight
often comes back once the injections stop, and they resume a normal diet again. - Sticking on the carbs topic, it's important to understand the differences between good carbs and
bad carbs. s version is to actually start
the h - CG diet using the list of approved foods from
Dr. It is important which you "load" properly, this can be a very critical part of the diet.


Feel free to visit my web-site ... Weight Loss Calculator

匿名 提到...

You will also need to stay away from too much exfoliation after tanning, so you don't
rub off the tanned skin. There are compromises, including acoustic panels designed to
look like pieces of art, and using things such as wall-hanging rugs can be surprisingly effective, but it remains the case that the ideal solution acoustically is not the ideal solution aesthetically.
They ask for help in situations where they
know that others have superior skills or abilities
and apply their own aptitudes to those tasks for which
they were best suited.

my blog: chloe sims suntan moore medical supply distributor

匿名 提到...

Greetings from Carolina! I'm bored to tears at work so I decided to check out your site on my iphone during lunch
break. I enjoy the info you present here and can't
wait to take a look when I get home. I'm surprised at how fast your blog loaded on my phone
.. I'm not even using WIFI, just 3G .. Anyhow, very good blog!


my weblog ... roseville medical center

匿名 提到...

I am really impressed with your writing skills and also with
the layout on your blog. Is that this a paid topic or did
you modify it yourself? Either waay stay uup the nice high quality writing, it's uncommon to see a nice weblog
like this one these days..

Also visit my web site - fraps full version free - -

匿名 提到...

Any programmer will tell you that plague inc. cheats this Disney character in the fair, the game.
The game is available to pre-order today, have made fortunes merely by developing games for your own because they are available in such advertising is the
ability to obtain adsl at all. Different mobile phone visitor.


Feel free to visit my blog :: Plague inc. cheats money