1、spring orm support
與原來使用LocalSessionFactoryBean相比,變動不大(AnnotationSessionFactoryBean本來就是從LocalSessionFactoryBean類繼承過來的嘛)
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean
parent="AbstractSessionFactory">
<property name="annotatedClasses">
<list>
<value>xxx.xxx.xxx.domain.Account</value>
</list>
</property>
</bean>
<bean id="AbstractSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
abstract="true">
<property name="dataSource" ref="DataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
<prop key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop>
</props>
</property>
<property name="lobHandler" ref="DefaultLobHandler" />
</bean>
2、id的配置
非常簡單,在id的getter上面加個“@Id”就可以了。此時采用的id策略是javax.persistence.GenerationType.AUTO,也可以再加上 “@GeneratedValue(generator =GenerationType.IDENTITY|GenerationType.SEQUENCE|GenerationType.TABLE)”換成其它策略。
我的應用采用的是hibernate的uuid策略,就不得不在這兒使用hibernate的擴展了
@Id
@Column(length = 32)
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
3、級聯策略
在ejb3-persistence.jar中只定義了 ALL、MERGE、PERSIST、REFRESH、REMOVE,比較惡心的就是,刪除對象的時候,并不會級聯刪除關聯對象,而是用update xx set parent_id=null where parent_id=?這類語句把關系干掉了事。不得已,在這兒用了hibernate的DELETE_ORPHAN。
@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里面沒有找到cache的配置,繼續請出hibernate來干活
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
@Entity
@Table(name = "T_INFO")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
5、自定義字段類型
我的POJO中有一個private String content;的屬性,按ejb3配成@Lob后,被處理成了text類型,text 64k的存儲容量還是比較可憐了。
@Lob
@Column(columnDefinition = "LongText")
posted on 2008-08-30 23:21
lvq810 閱讀(1228)
評論(0) 編輯 收藏 所屬分類:
Open Framekwork