posts - 15,  comments - 8,  trackbacks - 0
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 阅读(1213) 评论(0)  编辑  收藏 所属分类: Open Framekwork

只有注册用户登录后才能发表评论。


网站导航: