Hibernate定制Tuplizer

Hibernate定制Tuplizer,使用@Tuplizer注解

 本文转自http://www.521100.net/hibernate-tuplizer.html

   首先,第一步在Hinbernate实体上增加注解@Tuplizer,它有两参数
         1.entityMode 默认pojo
         2.2.impl 自己的Tuplizer实现类,填写完整的类名称 com.woaitech.WiPojoEntityTuplizer

   其次,实现自己的Tuplizer,如下<br />
       public class WiPojoEntityTuplizer extends PojoEntityTuplizer {
           public WiPojoEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) {
               super(entityMetamodel, mappedEntity);
             }


            protected Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity) {
               return mappedProperty.getGetter( mappedEntity.getMappedClass() );
            }


            protected Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity) {
               return mappedProperty.getSetter( mappedEntity.getMappedClass() );
            }
       }
   上面的代码只是简单重写了PojoEntityTulizer的两个方法,他们的作用的是构建属性访问器。那么如果有需要就可以返回自己的属性访问器,来达到定制的目的。
   它的作用如doc上描述一样•extract values from and inject values into such a data structure 
   连接了实体到数据库。

  

posted on 2015-04-17 17:25  我爱1和0  阅读(356)  评论(0)    收藏  举报

导航