小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

嘗試hibernate annotations

 nbtymm 2007-02-06
最近開始嘗試hibernate annotations,終于成功的將手上一個(gè)小應(yīng)用轉(zhuǎn)為annotations

1、spring orm support
與原來(lái)使用LocalSessionFactoryBean相比,變動(dòng)不大(AnnotationSessionFactoryBean本來(lái)就是從LocalSessionFactoryBean類繼承過(guò)來(lái)的嘛)
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--> 1    <bean
 2         id="sessionFactory"

 3         class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
 4         parent="AbstractSessionFactory">
 5         <property name="annotatedClasses">
 6             <list>
 7                 <value>xxx.xxx.xxx.domain.Accountvalue>
 8             list>
 9         property>
10     bean>
11     <bean
12         id="AbstractSessionFactory"

13         class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
14         abstract="true">
15         <property
16             name="dataSource"

17             ref="DataSource" />
18         <property name="hibernateProperties">
19             <props>
20                 <prop key="hibernate.dialect">${hibernate.dialect}prop>
21                 <prop key="hibernate.show_sql">${hibernate.show_sql}prop>
22                 <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}prop>
23                 <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}prop>
24                 <prop key="hibernate.cache.provider_class">${hibernate.cache.provider_class}prop>
25             props>
26         property>
27         <property
28             name="lobHandler"

29             ref="DefaultLobHandler" />
30     bean>
2、id的配置
非常簡(jiǎn)單,在id的getter上面加個(gè)“@Id”就可以了。此時(shí)采用的id策略是javax.persistence.GenerationType.AUTO,也可以再加上“@GeneratedValue(generator =GenerationType.IDENTITY|GenerationType.SEQUENCE|GenerationType.TABLE)”換成其它策略。
我的應(yīng)用采用的是hibernate的uuid策略,就不得不在這兒使用hibernate的擴(kuò)展了
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->  @Id
  @Column(length 
= 32
)
  @GeneratedValue(generator 
= "system-uuid"
)
  @GenericGenerator(name 
= "system-uuid", strategy = "uuid")

3、級(jí)聯(lián)策略
在ejb3-persistence.jar中只定義了ALL、MERGE、PERSIST、REFRESH、REMOVE,比較惡心的就是,刪除對(duì)象的時(shí)候,并不會(huì)級(jí)聯(lián)刪除關(guān)聯(lián)對(duì)象,而是用update xx set parent_id=null where parent_id=?這類語(yǔ)句把關(guān)系干掉了事。不得已,在這兒用了hibernate的DELETE_ORPHAN。
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->  @OneToMany(targetEntity = Attachment.class)
  @Cascade(value 
=
 {org.hibernate.annotations.CascadeType.DELETE_ORPHAN,
      org.hibernate.annotations.CascadeType.ALL})
  @JoinColumn(name 
= "info_id")
4、CACHE
ejb3-persistence.jar里面沒(méi)有找到cache的配置,繼續(xù)請(qǐng)出hibernate來(lái)干活
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->import org.hibernate.annotations.Cache;
import
 org.hibernate.annotations.CacheConcurrencyStrategy;

@Entity
@Table(name 
= "T_INFO"
)
@Cache(usage 
= CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
5、自定義字段類型
我的POJO中有一個(gè)private String content;的屬性,按ejb3配成@Lob后,被處理成了text類型,text 64k的存儲(chǔ)容量還是比較可憐了。
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->  @Lob
  @Column(columnDefinition 
= "LongText")

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多